我正嘗試用另一個主機發送一封電子郵件,每當我收到這個error-> Mailer Error: SMTP connect() failed
。這裏是我的代碼無法使用PHP連接到SMTP
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = ' host IP ';
$mail->Port = 587;
$mail->SMTPSecure = 'ssl'; // I had also tried with TLS
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->setFrom('[email protected]', 'MY Personal');
$mail->addAddress($To);
if($MoreAddresses != "")
{
foreach($MoreAddresses as $Address)
{
$mail->addAddress($Address);
}
}
$mail->Subject = $Subject;
$mail->msgHTML($Body);
$mail->AltBody = 'This email contains HTML contents.';
if($MoreAddresses != "")
{
foreach($MoreAddresses as $Address)
{
$mail->addAddress($Address);
}
}
$mail->Subject = $Subject;
$mail->msgHTML($Body);
$mail->AltBody = 'This email contains HTML contents.';
if (!$mail->send())
{
return "Mailer Error: " . $mail->ErrorInfo;
}
else
{
return "Message sent!";
}
我曾嘗試過許多問題,但無法幫助我。
必須有更多的錯誤消息在您的日誌中。調查。 – ksimka
您可能會先問自己爲什麼要執行兩次'MoreAddresses'處理。 – RiggsFolly
然後問問自己用if($ MoreAddresses!=「」)' – RiggsFolly