phpmailer无法连接到SMTP
问题描述:
嗨,我收到此消息,我不知道问题在哪里。 在我的php.ini中,我已经取消了extension = php_openssl.dll的行,但它仍然不起作用。任何建议是受欢迎的。phpmailer无法连接到SMTP
邮件无法发送。邮件错误:SMTP错误:无法连接到SMTP主机。
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->Port = 465; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'mattonirestaurace'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->From = '[email protected]';
$mail->FromName = 'Your From name';
$mail->AddAddress('[email protected]', 'Josh Adams'); // Add a recipient
$mail->AddAddress('[email protected]'); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$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;
exit;
}
echo 'Message has been sent';
?>
您已经将您的代码基于一个过时的示例,并且您使用的是旧版本的PHPMailer。 [获取最新版本](https://github.com/PHPMailer/PHPMailer)并阅读随附的文档和示例。将来,在发布之前进行搜索。 – Synchro
[PHPMailer:SMTP错误:无法连接到SMTP主机]的可能重复(http://*.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host) – Synchro