我在我的帐户上启用了不太安全的应用程序,但仍然是相同的错误
。
无法发送邮件。邮件程序错误:SMTP connect() 失败
我尝试使用免费主机 000webhost。这是我的代码
require 'PHPMailerAutoload.php'; $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 = 'leets@gmail.com'; // SMTP username $mail->Password = 'private'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to $mail->setFrom('leets@gmail.com', 'tEst'); $mail->addAddress('leets@gmail.com'); // Add a recipient $mail->addAddress('ellen@example.com'); // Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'Hello ,Click On the link to reset password'; $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'; } ?>
请帮助。
最佳答案
更改为 587 端口有帮助吗?
smtp.Host = "smtp.gmail.com"; smtp.Port = 587;
关于PHPMailer 无法工作 000webhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43020791/