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 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52
  • ¥100 只改动本课件的 cal_portfolio_weight_series(decision_date), 跑完本课件。设计一个信息比率尽量高的策略。
  • ¥20 如何在visual studio 2022中添加ImageMagick库
  • ¥50 如何实现uniapp编译的微信小程序做可回溯视频
  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。