godaddy php mail,如何使用godaddy web主机上的phpmailer通过365发送电子邮件

我要用phpmailer lib通过365发送电子邮件。

这是我的配置

MAIL_DRIVER=smtp

MAIL_HOST=smtp.office365.com

MAIL_PORT=587

MAIL_USERNAME=support@xxxxx.com

MAIL_PASSWORD=XXXXXX

MAIL_ENCRYPTION=STARTTLS

以下代码是发送电子邮件的函数

public function __construct()

{

date_default_timezone_set('America/Virgin');

$this->mail = new \PHPMailer;

$this->mail->isSMTP();

$this->mail->CharSet = 'UTF-8';

//Ask for HTML-friendly debug output

$this->mail->Debugoutput = 'html';

//Set the hostname of the mail server

$this->mail->Host = getenv("MAIL_HOST"); //'ssl://smtp.gmail.com';

$this->mail->Port = getenv("MAIL_PORT");

//Set the encryption system to use - ssl (deprecated) or tls

// $this->mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication

$this->mail->SMTPAuth = true;

$this->mail->Username = getenv("MAIL_USERNAME");

$this->mail->Password = getenv("MAIL_PASSWORD");

$this->mail->SMTPSecure = getenv("MAIL_ENCRYPTION");

$this->setSender(

$this->sender_email,

$this->sender_password,

$this->sender_display_name,

$this->sender_display_email,

$this->sender_reply_to_name,

$this->sender_reply_to_email

);

}

public function sendEmail($to_email, $to_name, $subject, $message, $template_name = '')

{

//Set who the message is to be sent to

$this->mail->addAddress($this->trim_input($to_email), $this->trim_input($to_name));

//Set the subject line

$this->mail->Subject = $subject;

//Read an HTML message body from an external file, convert referenced images to embedded,

//convert HTML into a basic plain-text alternative body

$this->mail->msgHTML($template_name);

//Replace the plain text body with one created manually

$this->mail->AltBody = $message;

//send the message, check for errors

if (!$this->mail->send()) {

return false;

// echo "Mailer Error: " . $this->mail->ErrorInfo;

} else {

return true;

}

}

我尝试在本地服务器和数字海洋服务器上发送电子邮件

在这种情况下,我已经正确地发送和接收了电子邮件,

但在godaddy服务器中有错误

怎么解决?

谢谢你的预付款。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值