simple_man_11 Posted March 27, 2008 Share Posted March 27, 2008 Even though the below query/array pulls back only one email address, it sends two emails to the same address... Basically it sends a duplicate email and I am not sure why as the code only runs once... and stores the email in the .txt file below.. any help would be great, thanks in advance ! <?php include ('config.php'); //if ($newsletter==1) //{ $query = "select email from test "; $result= mysql_query($query); while ($array= mysql_fetch_assoc($result)) { $emailit = $array["email"] ; require_once ('class.phpmailer.php'); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = "localhost"; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "*******"; // SMTP username $mail->Password = "******"; // SMTP password $mail->From = "dana@****.org"; $mail->FromName = "Reveille Newsletter"; //$mail->AddAddress = "$emailit" ; $mail->AddAddress("$emailit"); // optional name //$mail->AddAddress("eric@***.org"); $mail->AddReplyTo("dana@***.org"); $mail->WordWrap = 50; // set word wrap //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); $mail->IsHTML(true); // send as HTML $mail->Subject ="Newsletter"; $mail->Body = "This is a test to see if you received this email. If you would like to get emails from Pointman at a different email address, please let us know." ; $mail->AltBody = "This is the text-only body"; if(!$mail->Send()) { // echo "Message was not sent, please try again. <p>"; // echo "Mailer Error: " . $mail->ErrorInfo; //write bad email address to file $File = "email_error.txt"; $Handle = fopen($File, "a"); fwrite($Handle, $emailit ); fwrite($Handle, "\n" ); fclose($Handle); //exit; } // message is sent! //echo "<meta http-equiv='refresh' content='3; url=http://www.***.org'>"; //echo "<center><br>A Represenative will be contacting you shortly about your inquery.</center>"; echo "email sent to the email address in file: $emailit"; if($mail->Send()) { // echo "Message was not sent, please try again. <p>"; // echo "Mailer Error: " . $mail->ErrorInfo; //write bad email address to file $File = "email_good.txt"; $Handle = fopen($File, "a"); fwrite($Handle, $emailit ); fwrite($Handle, "\n" ); fclose($Handle); //exit; } } //} //else //{ //echo "No form was submitted !"; //} ?> Quote Link to comment Share on other sites More sharing options...
schilly Posted March 27, 2008 Share Posted March 27, 2008 I believe your calling $mail->Send(); twice = 2 emails. <?php if(!$mail->Send()) { // echo "Message was not sent, please try again. <p>"; // echo "Mailer Error: " . $mail->ErrorInfo; //write bad email address to file $File = "email_error.txt"; $Handle = fopen($File, "a"); fwrite($Handle, $emailit ); fwrite($Handle, "\n" ); fclose($Handle); //exit; } // message is sent! //echo "<meta http-equiv='refresh' content='3; url=http://www.***.org'>"; //echo "<center><br>A Represenative will be contacting you shortly about your inquery.</center>"; echo "email sent to the email address in file: $emailit"; if($mail->Send()) { // echo "Message was not sent, please try again. <p>"; // echo "Mailer Error: " . $mail->ErrorInfo; //write bad email address to file $File = "email_good.txt"; $Handle = fopen($File, "a"); fwrite($Handle, $emailit ); fwrite($Handle, "\n" ); fclose($Handle); //exit; } } //} //else //{ //echo "No form was submitted !"; //} ?> I think you want: <?php if(!$mail->Send()) { // echo "Message was not sent, please try again. <p>"; // echo "Mailer Error: " . $mail->ErrorInfo; //write bad email address to file $File = "email_error.txt"; $Handle = fopen($File, "a"); fwrite($Handle, $emailit ); fwrite($Handle, "\n" ); fclose($Handle); //exit; } else { // echo "Message was not sent, please try again. <p>"; // echo "Mailer Error: " . $mail->ErrorInfo; //write bad email address to file $File = "email_good.txt"; $Handle = fopen($File, "a"); fwrite($Handle, $emailit ); fwrite($Handle, "\n" ); fclose($Handle); //exit; } ?> Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted March 27, 2008 Author Share Posted March 27, 2008 That fixed it, thank you ! I figured by saying: if(!$mail->Send()) { .... } then if($mail->Send()) { .... } it would have taken care of if in the sections only what applied (either the mail was sent, or it was not sent, then do this.) but I guess not. anyways thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.