473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

send multiple email using phpmailer, i am using Gmail SMTP

i am trying to send multiple mail using phpmailer. I have a problem. When i click send button, just zxc@gmail.com and abc@yahoo.com receives the message.

How to change it? I'm use Gmail SMTP send out.

There are 5 records in the database:

Here is my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. $body=$_POST['message'];
  5. $subject=$_POST['sub'];
  6.  
  7. //error_reporting(E_ALL);
  8. error_reporting(E_STRICT);
  9.  
  10. date_default_timezone_set('America/Toronto');
  11.  
  12. require_once("class.phpmailer.php");
  13.  
  14.  
  15. $con=mysql_connect("localhost","root","") or
  16. die("could not connect:".mysql_error());
  17.  
  18. mysql_select_db("bulkemail");
  19. $qry=mysql_query("SELECT * FROM email_id", $con);
  20. if(!$qry)
  21. {
  22. die("Query Failed: ". mysql_error());
  23. }
  24. while($row = mysql_fetch_array($qry))
  25. {
  26.  
  27. $id= $row['email'];
  28.  
  29. $mail             = new PHPMailer();
  30.  
  31. $mail->IsSMTP(); // telling the class to use SMTP
  32.  
  33. $mail->Host       = "stmp.gmail.com"; // SMTP server
  34.  
  35. $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
  36.  
  37. // 1 = errors and messages
  38.  
  39. // 2 = messages only
  40.  
  41. $mail->SMTPAuth   = true;                  // enable SMTP authentication
  42.  
  43. $mail->SMTPSecure = 'ssl'; 
  44.  
  45. $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  46.  
  47. $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
  48.  
  49. $mail->CharSet = "big5";
  50.  
  51. $mail->Username   = "abc@gmail.com";  // GMAIL username
  52.  
  53. $mail->Password   = "......";            // GMAIL password
  54.  
  55. $mail->SetFrom("abc@gmail.com", ''); // set reply id
  56.  
  57. $mail->AddReplyTo("abc@gmail.com",""); 
  58.  
  59. $mail->Subject    = ($subject); // subject
  60.  
  61. $mail->AltBody    = "Hey, check out this new post on www.techaltum.in"; // optional, comment out and test
  62.  
  63. $mail->MsgHTML("$body"); // message 
  64.  
  65. $address = ($id);
  66.  
  67. $mail->AddAddress($address);
  68.  
  69.  
  70. if(!$mail->Send()) {
  71.   echo "Mailer Error: " . $mail->ErrorInfo;
  72. } else {
  73.   echo "Message sent!";
  74. }
  75. }
  76. ?>
  77.  
Jul 5 '13 #1
14 7817
Luuk
1,047 Expert 1GB
Line#33 is wrong:
Expand|Select|Wrap|Line Numbers
  1. $mail->Host       = "stmp.gmail.com"; // SMTP server
should it not be:
Expand|Select|Wrap|Line Numbers
  1. $mail->Host       = "smtp.gmail.com"; // SMTP server
?

oooh, wait, that is corrected on line #45 ;)
Jul 5 '13 #2
Luuk
1,047 Expert 1GB
What is the output of this script?

Is it 5 times "Message sent!" ?

Is there any extra output for line #35 "$mail->SMTPDebug = 1;" ??
Jul 5 '13 #3
There is 5 e-mail id's are in my Database but only 2 e-mail id's receive mail but other one didn't receive mail
Jul 6 '13 #4
Luuk
1,047 Expert 1GB
I just copied your script

changed all references to 'abc@gmail.com' to my_own_address@gmail.com

changed line4 to: $body="test";
changed line5 to: $subject="test";

change database stuff at line #15 and #18 to match my database

entered 5 emailaddresses in this table...

and it worked.....

I therefore see two options:
1) your password is wrong (line #35)
(re-check your password)
2) emailaddresses in database are wrong.
maybe change line #27 to check the addresses:
Expand|Select|Wrap|Line Numbers
  1. $id= $row['email']; echo $id;
Jul 6 '13 #5
i have check all my code which you suggest but still i am not able to send more than 2 mail
Jul 8 '13 #6
Luuk
1,047 Expert 1GB
Again: What is the output of this script?

Or, what happens if you put these addreses in your database:
abc+1@gmail.com
abc+2@gmail.com
abc+3@gmail.com
abc+4@gmail.com
abc+5@gmail.com

You should receive those 5 messages in the box of abc@gmail.com
Jul 8 '13 #7
the output is
abc1@gmail.com Message sent!
abc2@gmail.com Message sent!
abc3@gmail.com
abc4@gmail.com
abc5@gmail.com

and only 2 email id receive mail
Jul 8 '13 #8
Luuk
1,047 Expert 1GB
hmmzzzzz, why did you leave out the '+' ??

But i'm afraid i don't see an answer to your problem.....
Jul 8 '13 #9
can you send me you coding
Jul 8 '13 #10
Luuk
1,047 Expert 1GB
it's the same as your code, just different emailaddresses
and i downloaded phpmailer from here
Jul 8 '13 #11
now i can send email to more people but now i am getting new problem when i send mail then first email will go to one person, the second email sent will go to that same person plus another, the third one will go to those two plus one more, and so on.
Jul 9 '13 #12
Rabbit
12,516 Expert Mod 8TB
That's because on line 67 of your original code, you call AddAddress. That will add an address to the To line, it doesn't replace what's there. You need to call ClearAddresses() before you add an address.
Jul 9 '13 #13
Luuk
1,047 Expert 1GB
@Rabbit:
i thought it wen ok, because of the 'new' in line #29:
Expand|Select|Wrap|Line Numbers
  1. $mail             = new PHPMailer();
Jul 9 '13 #14
Rabbit
12,516 Expert Mod 8TB
Refer to the documentation's example here: http://phpmailer.worxware.com/index.php?pg=exampledb. Notice their use of ClearAddresses at the bottom. There is no need to keep creating instances and setting values that only need to be set once.
Jul 9 '13 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michele | last post by:
Hi, I need to send the same Email to different people. I'm using Outlook XP and VB.Net. I tryed with the following code: Dim oOutL As Outlook.Application Dim oMail As Outlook._MailItem oOutL...
1
by: Wells Wang | last post by:
Hi, Everybody: Sorry to bother you. I am trying to use the code below to send an email with asp.net2.0& win XP. But it failed. On my laptop I can use outlook2003 to send email. If you are...
2
by: prasenjit2007 | last post by:
Hello, can u help me sending Email with attachments using the Class phpMailer. On the website I have a link to an html form in which I input the parameters with the names 1)from(textbox name)...
1
by: akuva | last post by:
I have to send more than 100s of email using a php code if i use mail function whether it will be sent to spam or inbox. If it is sent to spam which is the other way to send mass email from php. i...
0
by: =?ISO-8859-1?Q?Jo=E3o_Morais?= | last post by:
Hi there guys, I've been using PHPmailer for a while, and now I'm using it with SMTP enabled, my problem is: Although I do define my charset as iso-8859-1, my body message will appear with...
1
by: mynkow | last post by:
I know it is tot possible. I just want someone to confirm that there is no way to send an email using only HTML code. If I am wrong will be greate. 10x
5
vivekgs2007
by: vivekgs2007 | last post by:
HI to all, I downloaded the Php Mailer Function, I embedded it to my Feedback page, It is not giving any error, But the mail is not going, I don't no where i gone wrong...Please help me...
4
KeredDrahcir
by: KeredDrahcir | last post by:
I'm trying to send an E-mail using PHPMailer and although everything look okay, it's not coming through. Can anyone help? I'm posting my information from a form. require_once...
11
by: londres9b | last post by:
I want to send multiple emails from php with one unique script. The emails are from a mysql database table. How can I achieve this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.