homepage Welcome to WebmasterWorld Guest from 50.17.7.84
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Sending many mails using phpmailer
kkonline




msg:3483283
 1:03 pm on Oct 21, 2007 (gmt 0)

Hi,
I am using the following code to send mails (the emails are stored in the database).

The problem is If there are 5 mails in the database then the following code sends 5 emails to each of the 5 emails... i mean mail1@example.com then the second mail has to recipients as mail1@example.com and mail2@example.com then the third recipient gets cc as mail1@example.com, mail2@example.com and mail3@example.com and so on... and the loop continues ... what to do

$subject="Your friend sends you an interesting link";
$message="Greetings,

Your friend wants you to check the following link:
http://example.com";

$mail->FromName = "Test";
$mail->From = "test@example2.com";

$mail->AddReplyTo("test@example2.com", "Test");

$mail->Subject = $subject;
$mail->Body = $message;
$mail->WordWrap = 65;

$sql = "SELECT * FROM contacts";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$value=$row['email'];

$mail->AddAddress($value);

if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent.';

}
}

I want to send the newsletter something like blind carbon copy .

[edited by: eelixduppy at 6:25 am (utc) on Oct. 22, 2007]
[edit reason] changed to example.com [/edit]

 

Steerpike




msg:3483668
 5:18 am on Oct 22, 2007 (gmt 0)

Move
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent.';

}
Outside the while loop
(So you have)
while($row = mysql_fetch_array($result)){
$value=$row['email'];

$mail->AddAddress($value);
}
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent.';

}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved