Reputation: 547
When I'm sending a test message via PHPmailer (SMTP) my email appends to the recepients list. Here is what recipient sees in inbox email
To: [email protected], Name <[email protected]>
The second email is mine. How can I stop this?
Here is my code
function send_email($to, $fromName, $subject, $message, $contentType='text', $smtp_opts) {
$mail = new PHPmailer();
$mail->SetFrom($smtp_opts['fromEmail'], $fromName);
$mail->Subject = $subject;
$mail->Mailer = 'smtp';
$mail->AddAddress($to);
$mail->CharSet = "UTF-8";
$mail->IsHTML($contentType=='html');
$mail->Host = $smtp_opts['host'];
$mail->SMTPAuth = (bool)$smtp_opts['auth'];
if ($mail->SMTPAuth) {
$mail->Username = $smtp_opts['username'];
$mail->Password = $smtp_opts['password'];
}
$mail->Body = $message;
$mail->AddAddress($smtp_opts['fromEmail'], $fromName);
$result = $mail->Send();
$mail->ClearAddresses();
$mail->ClearAttachments();
return $result;
}
$smtp_opts = array( ... ); // host, port, fromEmail, auth, username, password
send_email('[email protected]', 'Name', 'Subj', 'Msg', 'html', $smtp_opts);
Upvotes: 1
Views: 1912
Reputation: 387
I think the problem is in this line $mail->AddAddress($smtp_opts['fromEmail'], $fromName);
Upvotes: 1
Reputation: 2598
$mail->AddAddress($smtp_opts['fromEmail'], $fromName);
If I am not mistaken, this command adds another recipient to the list of recipients. Try to remove it and send another test E-Mail. You shouldn't be getting the copy-mail then.
Upvotes: 4