Two emails when sent via SMTP
If you set the To and / or Recipient header multiple times, the SMTP server may interpret it as a separate email address, so you will receive multiple emails.
I would recommend using the PEAR Mail class. Very easy to use and handles most of the work for you. It supports multiple backends including SMTP. Likewise, if you want to extend your class to send HTML emails, the Mail_Mime class handles this very nicely by providing methods to set the plain text body and HTML body (in case the recipient does not support HTML).
a source to share
function send_email($from, $fromname, $to, $subject, $body, $alt = '')
{
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try
{
$mail->Host = 'localhost'; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
//$mail->AddReplyTo($from, $fromname);
$mail->AddAddress($to);
$mail->SetFrom($from, $fromname);
$mail->Subject = $subject;
//$mail->AltBody = $alt; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
echo 'Message Sent OK';
}
catch (phpmailerException $e)
{
echo $e->errorMessage(); //Pretty error messages from PHPMailer
}
catch (Exception $e)
{
echo $e->getMessage(); //Boring error messages from anything else!
}
}
What the current feature is so far
a source to share
Depending on your code, if it is the class that is at fault, you expect to receive a "Message sent OK" message twice (I don't understand why this will happen). If you don't, I would look at your SMTP server (perhaps via a call to support).
I am assuming you have disabled answer-to-answer to rule it out as the reason in this case? Note. I am not suggesting that this will affect anything (other than you, it will most likely be regarded as spam).
BTW, I switched from PHPMailer to Swift Mailer a while ago and have never looked back. If you are not getting any joy from support, I would try at least testing with Swift Mailer.
a source to share