dongzhong6675 2015-03-12 00:20
浏览 61
已采纳

更改phpmailer的FROM地址

How is phpmailer's FROM address changed? I expected the following to work, however, all emails sent use the the send from email address set by the first occurrence of 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. 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.

  • 写回答

1条回答 默认 最新

  • douxiajia6104 2015-03-12 00:41
    关注

    The property Sender is set once when calling the method setFrom. 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.

    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?
     */
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值