當我發送的電子郵件從服務器然後它給我的兩個錯誤 -無法連接到SMTP主機。消息無法發送
SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
我發現很多暗示對堆棧溢出另一個答案,但不起作用。我試了端口號465/587/65。即使下面的代碼適用於我的本地系統如果我設置端口587.但在服務器中,它不起作用。
require('class.phpmailer.php');
require('class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Username = "FromEmailId";
$mail->Password = "Password";
$mail->Port = 465;
$mail->From = "FromEmailId";
$mail->AddAddress("ToEmail");
$mail->IsHTML(true);
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
我認爲這是服務器端錯誤 –
@Yogesh。感謝回覆。但是我怎麼能解決它。? –
親愛的我也面臨這個問題,但不是任何解決方案 –