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 jsp,如何使用户名输出为中文(语言-javascript)
    • ¥20 文件读写,但中文乱码
    • ¥15 PowerBI中如何做到按数值向下取数
    • ¥15 设计quartus maxⅡ :Verilog-FPGA(0
    • ¥15 windows server 2022 datacenter安全策略配置 没有权限问题
    • ¥20 寻找dspace有偿技术支持
    • ¥30 深度学习的模型融合问题
    • ¥20 数电实验Verilog编程
    • ¥15 机器人MATLAB仿真示教占内存过大
    • ¥15 JSR233已经使用但是仍无法将csv数据放到一个list里显示出来,如何解决?