PHPMailer不适用于Gmail SMTP
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHPMailer不适用于Gmail SMTP,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1813字,纯文字阅读大概需要3分钟。
内容图文
![PHPMailer不适用于Gmail SMTP](/upload/InfoBanner/zyjiaocheng/796/6c8d72d1a57a47a0abb62958ba65a885.jpg)
以下代码适用于我的xampp本地服务器,但不会在远程主机上发送电子邮件.我收到此错误:
Message could not be sent.Mailer Error: SMTP connect() failed
require_once('header.php');
require_once('PHPMailer/PHPMailerAutoload.php');
function sendMail($address, $message){
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail@gmail.com'; // SMTP username
$mail->Password = 'mypass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom('mymail@gmail.com', 'ID Test'); // Add a recipient
$mail->addAddress($address); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Twitter search';
$mail->Body = $message;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
}
解决方法:
在使用设置为TLS身份验证协议和端口号587的Gmail服务器时,我在使用PHPMailer时遇到了麻烦.我不记得那个组合曾经为我工作过.但是,我从来没有遇到过使用SSL / 465的问题.
而不是这个:
// Your Current Settings
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
试试这个:
// Updated Settings
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
更多信息:
> Google SMTP Settings
> Difference Between TLS and SSL
内容总结
以上是互联网集市为您收集整理的PHPMailer不适用于Gmail SMTP全部内容,希望文章能够帮你解决PHPMailer不适用于Gmail SMTP所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。