Reputation: 375
Here it is a working script in phpmailer. It sends emails from the "Maile" table BUT after the emails are sent I see only email has been sent. If there were 10 emails I get 10x - email has been sent. I would like to it to be shown like this - [email protected] - email has been sent. How should I do it? Thank You. Here is the code without the part showing the connection with the mail server...
<!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>
Upvotes: 0
Views: 1139
Reputation: 455
Give the following a try, its not tested and its like 00:30 so there may be a mistake
<!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>
Upvotes: 1
Reputation: 455
I may have misunderstood the question entirely but it should just be a case of doing the following:
if($mail->Send()) {
echo $record["Maile"] . ' - E-mail has been sent';
} else {
echo $record["Maile"] . ' - E-mail has not been sent';
}
Upvotes: 1