如何回复电子邮件已发送?

时间:2015-12-28 20:48:22

标签: php email

这是phpmailer中的一个工作脚本。它发送来自" Maile"的电子邮件。表但在发送电子邮件后,我看到只发送了电子邮件。如果有10封电子邮件,我会收到10倍电子邮件 - 已发送电子邮件。我希望它显示如下 - xxxx@xxxx.xx - 已发送电子邮件。我该怎么办?谢谢。这是没有显示与邮件服务器连接的部分的代码...

 <!doctype html>
<html>
<head>
<meta charset="UTF-8">




<?php

$con = mysql_connect("XXXX","XXXX","XXXX");
if (!$con){
die("NOT connected: " . mysql_error());
}
mysql_select_db("test",$con);

    $query  = "SELECT Maile FROM Mailing";
    $result = mysql_query($query,$con);

while($record = mysql_fetch_array($result)){


    $mail->MsgHTML($body);
    $mail->AddAddress($record["Maile"]);


     if($mail->Send())    
        {                      
        echo 'E-mail has been sent'; 
        }            
    else    
        {           
        echo 'E-mail has not been sent';    
        }


    $mail->ClearAddresses();
    $mail->ClearAttachments();
}

  ?>  

</html>
</head>

2 个答案:

答案 0 :(得分:1)

我可能完全误解了这个问题,但这应该只是做以下事情:

if($mail->Send()) {                      
    echo $record["Maile"] . ' - E-mail has been sent'; 
} else {           
    echo $record["Maile"] . ' - E-mail has not been sent';    
}

答案 1 :(得分:1)

尝试以下内容,未经测试,00:30这样可能会出现错误

<!doctype html>
<html>
<head>
<meta charset="UTF-8">




<?php

$con = mysql_connect("XXXX","XXXX","XXXX");
if (!$con){
die("NOT connected: " . mysql_error());
}
mysql_select_db("test",$con);

$query  = "SELECT Maile FROM Mailing";
$result = mysql_query($query,$con);

echo '<table align="center" style="text-align:center; border:5px solid black;">';
echo '<tr><td>ID</td><td>Maile</td><td>Status</td></tr>'; //You missed ; here

while($record = mysql_fetch_array($result)){


$mail->MsgHTML($body);
$mail->AddAddress($record["Maile"]);


 if($mail->Send())    
    {                      
    echo '<tr>'; 
    echo '<td>'. $record["id"] .'</td>';                
    echo '<td>'.$record["Maile"] . '</td>';
    echo '<td>Success - Email sent</td>';
    echo '</tr>';
    }            
else    
    {           
    echo '<tr>'; 
    echo '<td>'. $record["id"] .'</td>';           
    echo '<td>'.$record["Maile"] . '</td>'; 
    echo '<td>Failed - Email NOT sent</td>';
    echo '</tr>';    
        }


    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
echo '</table>';
  ?>  

</html>
</head>