在使用smtp邮件类发送邮件时,当我在本地系统中使用smtp发送电子邮件代码时,我遇到了问题,但当我在活动服务器上尝试使用该代码时,每次smtp连接失败时,我都会收到错误。
我使用此代码使用smtp mailer类发送邮件。
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail@gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->From = 'myemail@gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('myemail@gmail.com', 'Joe User');
$mail->addAddress('myemail@gmail.com');
$mail->addReplyTo('myemail@gmail.com', 'Information');
$mail->addCC('myemail@gmail.com');
$mail->addBCC('myemail@gmail.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';}这是我的代码,它在本地工作,但不工作在实时服务器上。
我在我的php.ini文件中做了所有的设置,比如smtp和用户密码,但是仍然不能工作,所以请给我正确的解决方案或在实时服务器中工作的代码。
这是错误
2016-07-07 17:23:09 SMTP错误:连接服务器失败:网络不可达(101) 2016-07-07 17:23:09 SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting消息不能是sent.Mailer错误: SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
发布于 2017-04-11 16:48:44
您必须首先激活gmail,接受非安全应用程序。
发布于 2022-02-06 10:47:05
为发送者和接收方使用真实的电子邮件“确认密码”
$mail->SMTPSecure = 'tls';
至
$mail->SMTPSecure = 'ssl';
//tls for localhost and ssl for host server 'onligne'$mail->港口= 465;/或587
可能为你工作:)
https://stackoverflow.com/questions/38251047
复制相似问题