phpmailer的FROM地址是怎么变的?我希望以下内容能够正常工作,但是,所有发送的电子邮件都使用第一次出现 SetFrom()
时设置的发件人电子邮件地址。
$mail = new myPHPMailer(true);
$mail->SMTPDebug=2;
$mail->Subject = "My Subject";
$mail->MsgHTML('My Message');
$mail->AddReplyTo('me@myworkcompany.com');
$mail->ClearAllRecipients();
$mail->SetFrom('me@myworkcompany.com');
$mail->AddAddress("someoneelse@otherdomain.com");
$mail->Send();
$mail->ClearAllRecipients();
$mail->SetFrom('default@mydomain.com'); //Does not update FROM address!
$mail->AddAddress("someoneelse@myworkcompany.com");
$mail->Send();
附言。我为什么要这样做?我发现一些公司将他们的电子邮件路由器设置为拒绝所有传入的外部电子邮件,这些电子邮件的发件人电子邮件顶级域与他们自己的相同。
最佳答案
属性 Sender 在调用方法 setFrom 时设置一次。没有单独设置发件人的方法。但是你可以使用
$mail->Sender = <newvaluehere>;
或
$mail->set('Sender', <NEWVALUEHERE>);
我还想建议不要使用这个库,它几乎不一致,而且看起来也不适合生产。您可能会考虑使用经过验证的软件包,例如 swiftmailer。
这个类似乎没有准备好生产的原因
/**
* Set or reset instance properties.
* You should avoid this function - it's more verbose, less efficient, more error-prone and
* harder to debug than setting properties directly.
* Usage Example:
* `$mail->set('SMTPSecure', 'tls');`
* is the same as:
* `$mail->SMTPSecure = 'tls';`
* @access public
* @param string $name The property name to set
* @param mixed $value The value to set the property to
* @return boolean
* @TODO Should this not be using the __set() magic function?
*/
关于php - 更改 phpmailer 的发件人地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28999868/