2016-03-02 119 views
-1

我正嘗試用另一個主機發送一封電子郵件,每當我收到這個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!"; 
    } 

我曾嘗試過許多問題,但無法幫助我。

+0

必須有更多的錯誤消息在您的日誌中。調查。 – ksimka

+0

您可能會先問自己爲什麼要執行兩次'MoreAddresses'處理。 – RiggsFolly

+1

然後問問自己用if($ MoreAddresses!=「」)' – RiggsFolly

回答

0

當您使用

$mail->Port = 587; 
$mail->SMTPSecure = 'ssl'; 

那麼端口是:TLS = 587,SSL = 465。

+0

將其添加到您的答案中,_將編輯link_不作爲評論。沒有人可以閱讀註釋 – RiggsFolly

+0

和端口25中的代碼.... –

+0

設置outMail服務器的SMTP端口 使用25或587 –

1
$mail->IsSMTP(); 
$mail->Host = "smtp.gmail.com"; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = "ssl"; 
$mail->Username = "[email protected]"; 
$mail->Password = "**********"; 
$mail->Port = "465"; 

這是一個工作配置。 試圖取代你有什麼

+0

否將其添加到您的原始答案。每個問題的一個答案是所有需要的 – RiggsFolly

+0

我已檢查過安全主機網絡,並顯示「000.000.000.000:465(urd)已打開。」它是否會在該主機中產生任何問題? –

+0

你嘗試簡單的PHP郵件功能,並檢查它的工作與否。 –

0

添加mail.php使用下面的代碼它的正常工作對我來說...

include "../Mail/Mail.php"; 

$from = "test<emai>"; 
$to = $toname."<".$tomail.">"; 
$subject = $subject; 
$body =$body; 
$host ="ssl://smtp.gmail.com"; 
$port = "465"; 
$username = "[email protected]"; 
$password = "123456"; 
$headers['From'] =$from; 
$headers['To'] = $to; 
$headers['Bcc'] = $from; 
$headers['Subject'] = $subject; 
$headers['Reply-To'] = 'no-replay<no-replay>'; 
$smtp = Mail::factory('smtp', 
array ('host' => $host,  'port' => $port, 
'auth' => true,  'username' => $username,  'password' => $password)); 
$mail = $smtp->send($to, $headers, $body); 
if (PEAR::isError($mail)) 
{ 
    $mail->getMessage() ; 
} 
1

此代碼的PHP郵件

$to = "".$_REQUEST['txtphp_to'].""; 
$subject = "Nullam id dolor id nibh ultricies vehicula."; 
$txt = "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. 
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam id dolor id nibh ultricies vehicula."; 
$headers = "From: $s_emailid" . "\r\n";// . 
if(mail($to,$subject,$txt,$headers)) 
{ 
echo "done"; 
} 
else 
{ 
echo "error"; 
} 
+1

同一個問題的三個答案有點過分。任何人都應該有一個答案。 _一旦一個國王總是一個國王,但是一旦騎士足夠_ – RiggsFolly

相關問題