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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵