简体   繁体   English

更改phpmailer的FROM地址

[英]Change phpmailer's FROM address

How is phpmailer's FROM address changed? phpmailer的FROM地址是如何更改的? I expected the following to work, however, all emails sent use the the send from email address set by the first occurrence of SetFrom() . 我希望以下工作正常,但是,所有发送的电子邮件都使用第一次出现的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();

PS. PS。 Why I wish to do this? 我为什么要这样做? I have found that some companies set up their e-mail routers to deny all incoming external emails which have a sender email top level domain the same as their own. 我发现有些公司设置了他们的电子邮件路由器来拒绝所有传入的外部电子邮件,这些电子邮件的发件人电子邮件顶级域名与他们自己的相同。

The property Sender is set once when calling the method setFrom. 调用方法setFrom时,属性Sender设置一次。 There is no method to individually set Sender. 没有单独设置发件人的方法。 However you can use 但是你可以使用

$mail->Sender = <newvaluehere>;

or 要么

$mail->set('Sender', <NEWVALUEHERE>);

Also I'd like to advice against using this library, it's hardly consistent nor does it seem production ready. 另外我想建议不要使用这个库,它几乎不一致,也不是生产就绪。 You might consider a proven package like swiftmailer. 您可能会考虑像swiftmailer这样经过验证的软件包。

Reason why this class does not seem production ready 这个类似乎没有生产就绪的原因

/**
 * 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?
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM