当我通过PHPmailer(SMTP)发送测试邮件时,我的电子邮件会附加到收件人列表中。以下是收件人在收件箱电子邮件中看到的内容
收件人:mail@mail.com,姓名< mail2@mail.com>
第二封电子邮件是我的。我怎么能阻止这个?
这是我的代码
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('mail@mail.com', 'Name', 'Subj', 'Msg', 'html', $smtp_opts);
答案 0 :(得分:4)
$mail->AddAddress($smtp_opts['fromEmail'], $fromName);
如果我没有弄错,此命令会将另一个收件人添加到收件人列表中。尝试删除它并发送另一个测试电子邮件。那时你不应该收到复制邮件。
答案 1 :(得分:1)
我认为问题出在这一行 $ mail-> AddAddress($ smtp_opts ['fromEmail'],$ fromName);