2012-08-27 33 views
4

我有一個SMTP問題。我創建了一個PHP腳本來發送電子郵件。要求是我需要發送來自'[email protected]'的電子郵件,但我需要回復來'[email protected]'在電子郵件中設置replyTo字段

我在reply-to標題字段中添加了[email protected]。我遇到的唯一問題是,當有人收到電子郵件並單擊答覆按鈕時,[email protected][email protected]都顯示在TO字段中。

是否有任何方法可以將[email protected]從TO字段中刪除,並且只顯示在reply-to字段中指定的電子郵件地址?

我使用的PHPMailer和代碼如下:

$this->phpmailer->IsSMTP(); 
    $this->phpmailer->Host = $server; 
    $this->phpmailer->Port = $port; 
    $this->phpmailer->SetFrom($fromEmail, $fromName); //this is [email protected] 
    $this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is [email protected] 
    $this->phpmailer->Subject = $subject; 
    $this->phpmailer->AltBody = $msgTXT; // non-html text 
    $this->phpmailer->MsgHTML($msgHTML); // html body-text 
    $this->phpmailer->AddAddress($email); 

回答

8

嘗試:

$this->phpmailer->IsSMTP(); 
$this->phpmailer->Host = $server; 
$this->phpmailer->Port = $port; 
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is [email protected] 
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is [email protected] 
$this->phpmailer->Subject = $subject; 
$this->phpmailer->MsgHTML($msgHTML); // html body-text 
$this->phpmailer->AddAddress($email); 

第一SetFrom之前嘗試設置AddReplyTo()。 phpmailer需要改變這種行爲。它將發件人地址添加到回覆字段。如果您在收件人地址之前先設置了回覆,則無法將您的收件人地址添加到回覆標題。

+0

這聽起來像一個好主意,我會檢查它,並讓你知道它是如何去 –

+0

是的,但它是一種「黑客」,所以你不需要編輯phpmailer。如果您只需發送一封普通電子郵件,則還可以完全停止使用phpmailer,並執行以下操作: 郵件('[email protected]','郵件主題','電子郵件正文','From:from.address @ example.com \ n回覆至:[email protected]「); 但您的服務器必須配置爲使用mail()。 – rationalboss

+1

需要注意的是,調用$ this-> phpmailer-> MsgHTML($ msgHTML)會同時設置AltBody,所以會有效地清除前一行中設置的AltBody – bumperbox

0

From a google search and first result

添加回復地址^

默認情況下,回覆地址將是FROM地址,除非你另有指定。那簡直就是電子郵件客戶端智能。但是,您可以讓電子郵件來自一個電子郵件地址,任何回覆都會發送到另一個電子郵件地址。具體方法如下:

$mailer->AddReplyTo('[email protected]', 'Billing Department');

注: 你可以有多個回覆地址,只需重複前面的代碼示例中的行,更改每個行的E-Mail地址。

您需要在收件人地址前添加此行。 P lease check out this for the solution to the same problem.

在這些例子中,你的代碼應該看起來像

$this->phpmailer->IsSMTP(); 
$this->phpmailer->Host = $server; 
$this->phpmailer->Port = $port; 
$this->phpmailer->AddReplyTo($replyEmail,$fromName); //this is [email protected] 
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is [email protected] 
$this->phpmailer->Subject = $subject; 
$this->phpmailer->AltBody = $msgTXT; // non-html text 
$this->phpmailer->MsgHTML($msgHTML); // html body-text 
$this->phpmailer->AddAddress($email); 
+0

@open_source是否爲您做了這項工作? – bretterer

相關問題