PHPMailer弹出的邮件没有被正确弹出



我写了一个PHP脚本,用来发送邮件。我从"mail@something.com并已将"返回路径"设置为bounce@something.com",但我仍然收到退回给发件人的邮件("mail@something.com").

这是精简的代码:

$this->mail = new PHPMailer();
$this->mail->isSMTP();
$this->mail->Host = 'host';
$this->mail->SMTPAuth = true;
$this->mail->Username = 'mail@something.com';
$this->mail->Password = 'pass';
$this->mail->SMTPSecure = 'tls';
$this->mail->Port = 25;
$this->mail->ReturnPath = 'bounce@something.com';
$this->mail->From = 'mail@something.com';
$this->mail->send();

我如何才能强制将退回的邮件转到退回邮件帐户?谢谢你的帮助!

不要使用ReturnPath,而是设置Sender。最近在PHPMailer(版本5.2.8)中禁用了对ReturnPath属性的支持,因为在发送时设置它是无效的。返回路径由接收方在收到邮件时添加,并通过将所需的返回路径放入Sender属性来设置,该属性在SMTP会话期间作为信封发送方传递。当您调用setFrom时,Sender会自动设置,但您可以覆盖它并直接设置它,如下所示:

$this->mail = new PHPMailer();
$this->mail->isSMTP();
$this->mail->Host = 'host';
$this->mail->SMTPAuth = true;
$this->mail->Username = 'mail@something.com';
$this->mail->Password = 'pass';
$this->mail->SMTPSecure = 'tls';
$this->mail->Port = 25;
$this->mail->setFrom('mail@something.com');
$this->mail->Sender = 'bounce@something.com';
$this->mail->send();

将此行添加到代码中:

$this->mail->AddReplyTo("youraccount@gmail.com","Your name");

相关内容

  • 没有找到相关文章

最新更新