1

当我通过 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);
4

2 回答 2

4
$mail->AddAddress($smtp_opts['fromEmail'], $fromName);

如果我没记错的话,这个命令会将另一个收件人添加到收件人列表中。尝试将其删除并发送另一封测试电子邮件。那时你不应该收到复制邮件。

于 2012-08-04T11:52:57.907 回答
1

我认为问题出在这一行 $mail->AddAddress($smtp_opts['fromEmail'], $fromName);

于 2012-08-04T11:57:06.240 回答