2017-10-06 44 views
-2

このスクリプトが完全に機能するまで、この3日間はこの問題に直面しています。今すぐエラーを取得:ここSMTP接続に失敗しました

SMTP ERROR: Failed to connect to server: (0) 2017-10-06 21:05:34 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting [email protected]

は私のスクリプトです:

require 'PHPMailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 
$mail->SMTPDebug = 2;     // Enable verbose debug output 
$mail->isSMTP();      // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;    // Enable SMTP authentication 
$mail->Username = '[email protected]'; // SMTP username 
$mail->Password = 'mypassword';  // SMTP password 
$mail->SMTPSecure = 'tls';    // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587; 
$mail->setFrom('[email protected]', 'Your Name'); 
$mail->addAddress('[email protected]', 'My Friend'); 
$mail->Subject = 'First PHPMailer Message'; 
$mail->Body  = 'Hi! This is my first e-mail sent through PHPMailer.'; 
if (!$mail->send()) { 
    echo 'Message was not sent.'; 
    echo 'Mailer error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent.'; 
} 

私はGmailのSMTP、またはそのような何かを使用して電子メールを送信するための設定を変更しているかもしれないと思います。

+3

を下回っているここで野生のアイデアがあります。 – Synchro

答えて

0

最後に、私はlocalhostから電子メールを送信できます。ここに私のコードです。インストールするには

  1. ダウンロードphpmailerの
  2. はスクリプトにオートロードクラスを追加
  3. (私は根の上に置く)プロジェクトに追加します。これとどのようにそれを修正する方法についてあなたのすべてを伝えるエラーメッセージでリンクをたどってみてください -
  4. コードの残りの部分は

     require "PHPMailer/PHPMailerAutoload.php"; 
         $mail = new PHPMailer; 
         $mail->SMTPOptions = array(
          'ssl' => array(
           'verify_peer' => false, 
           'verify_peer_name' => false, 
           'allow_self_signed' => true 
          ) 
         ); 
         //$mail->SMTPDebug = 2;         // Enable verbose debug output 
         $mail->isSMTP();          // Set mailer to use SMTP 
         $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers 
         $mail->SMTPAuth = true;        // Enable SMTP authentication 
         $mail->Username = '[email protected]';     // SMTP username 
         $mail->Password = 'securepass';       // SMTP password 
         $mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
         $mail->Port = 465;         // TCP port to connect to 
         //Recipients 
         $mail->setFrom('[email protected]', "Mailer"); 
         $mail->addAddress("[email protected]","receiver Name"); 
         $mail->isHTML(true);         
         $mail->Subject = "Subject"; 
         $mail->Body = "Body"; 
         $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
          if($mail->send()){ 
          return array("msg"=>msg("success","Email has been sent.<br>")); 
          } else { 
           return array("msg"=>msg("error","Email can't send.Try Again<br>")); 
          } 
    
関連する問題