【发布时间】:2015-11-27 05:53:14
【问题描述】:
美好的一天!
我试图让我的 phpmailer 在我的共享主机 (freehostia.com) 中工作,但我总是收到此错误。我的gmail的用户名和密码是正确的,剩下的设置是这样的:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'tls://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail@gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mymail@gmail.com', 'ASAPHOT Administrator'); // Add a recipient
$mail->addAddress('sorianorobertc@gmail.com'); // Name is optional
$mail->addReplyTo('mymail@gmail.com', 'ASAPHOT Administrator');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'it works';
$mail->Body = 'it works';
$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';
}
openssl 在php.ini 中也没有注释。我在这里错过了什么吗?谢谢。
完整的错误信息:
Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Permission denied (13)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
【问题讨论】:
-
那个问题不是这个问题的重复。
-
可能你的机器上没有防火墙,php 无法创建套接字。
-
@gtzinos phpmailer 需要防火墙吗? (无辜的问题。)