我正在使用此代码尝试使用 SMTP 发送电子邮件,但出现错误
<html>
<head>
<title>PHPMailer - SMTP basic test with authentication</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
phpinfo();
require("../class.phpmailer.php");
require("../class.smtp.php");
define("PHPMAILERHOST",'smtp.gmail.com');
date_default_timezone_set('Asia/Tehran');
$mail = new PHPMailer();
ini_set('display_errors', 1);
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = "465"; // SMTP Port
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure= "ssl"; // SMTP connection type
/************************************************** *********************************/
/************************************************** *********************************/
$mail->Username = "XXXXXXXXXX@gmail.com"; // SMTP username
$mail->Password = "XXXXXX"; // SMTP password
// Send email to :
$mail->AddAddress("masoudy.maryam@gmail.com"); // will receive the test email
/************************************************** *********************************/
/************************************************** *********************************/
//$mail->AddAddress("second-receiver@gmail.com", "Josh Adams");
//$mail->AddReplyTo("example@gmail.com", "Information");
$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "hahahahahahahahahahhahhahahahhahahha";
$mail->Body = '<html><meta http-equiv="content-type" content="text/php; charset=utf-8"/><body>
layay layayya رسید بگو
</body></html>
';
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
</body>
</html>
此代码在本地没有任何问题我可以在本地(wamp 服务器)发送电子邮件但在服务器中我有错误:
SMTP Error: Could not connect to SMTP host. Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.
我确定 ssl 端口已启用我调用 phpinfo() 我有这个结果请帮助我