2012-08-04 107 views
1

當我通過PHPmailer(SMTP)發送測試郵件時,我的電子郵件附加到收件人列表。以下是接受者看到的收件箱中的電子郵件PHPmailer發送複製到我的電子郵件

要:[email protected],名稱<[email protected]>

的第二封郵件是我的。我怎樣才能阻止呢?

這裏是我的代碼

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); 

回答

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

如果我沒有記錯的話,該命令將其他收件人的收件人列表。嘗試刪除它併發送另一個測試電子郵件。那麼你不應該收到複印郵件。

+0

哦,我的上帝!我從早上開始尋找這個錯誤...神聖sh_t!:( – 2012-08-04 11:56:16

+0

謝謝!我很慚愧... – 2012-08-04 11:58:45

+0

@NikitaGavrilov不要冒汗,我知道你有什麼感覺,有時只需要一眼就能發現問題,程序員花了數小時的時間尋找,儘管如果你接受了其中一個答案會很好:)謝謝。 – ATaylor 2012-08-04 12:06:26

1

我認爲問題出現在這一行 $ mail-> AddAddress($ smtp_opts ['fromEmail'],$ fromName);

相關問題