2017-08-10 5 views
0

メッセージがsent.Mailerエラーことができませんでした:SMTP接続()これは、電子メールを送信するために私のコードです

<?php 
 
     include('libs/PHPMailer-master/PHPMailerAutoload.php'); 
 
     //require 'PHPMailerAutoload.php'; 
 
     //require 'system/includes/PHPMailer/PHPMailerAutoload.php'; 
 
     $mail = new PHPMailer; 
 
     
 
     //$mail->SMTPDebug = 3;        // Enable verbose debug output 
 
     
 
     $mail->isSMTP();          // Set mailer to use SMTP 
 
     $mail->Host = gethostbyname("hostName"); // Specify main and backup SMTP servers 
 
     $mail->SMTPAuth = true;        // Enable SMTP authentication 
 
     //$mail->Username = '[email protected]';     // SMTP username 
 
     //$mail->Password = 'secret';       // SMTP password 
 
     $mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
 
     $mail->Port = 587;         // TCP port to connect to 
 
     
 
     $mail->setFrom([email protected], 'Mailer'); 
 
     $mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
 
     //$mail->addAddress('[email protected]');    // Name is optional 
 
     //$mail->addReplyTo('[email protected]', 'Information'); 
 
     //$mail->addCC('[email protected]'); 
 
     //$mail->addBCC('[email protected]'); 
 
     
 
     //$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 = 'Here is the subject'; 
 
     $mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
 
     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
 
     
 
     if(!$mail->send()) { 
 
      echo 'Message could not be sent.'; 
 
      echo 'Mailer Error: ' . $mail->ErrorInfo; 
 
     } else { 
 
      echo 'Message has been sent'; 
 
     } 
 
     ?>

sent.Mailerエラーになることができませんでしたメッセージに失敗しました。しかし、それは私に "メッセージを送信できませんでした"というエラーを表示します。メールエラー:SMTP connect()failed。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting "。誰かがそれの理由を知っていますか?

+0

https://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server –

+0

私は2つの理由が考えられます:あなたのホスティングロック発信コネクションポート587に接続しているか、SMTPの資格情報が間違っています。なぜ '$ mail-> Username'と' $ mail-> password'がコメントされたのですか?この2行のコメントを外して正しい資格情報を入力しようとしましたか?あなたのSMTPプロバイダが信用証明書を必要としない場合は、 '$ mail-> SMTPAuth'を' false'に設定する必要があります。 – Fabien

+0

私は2行のコメントを外して値を設定しました。それでも私は同じエラーが発生しています。 – sj111

答えて

0

削除するか、コメントアウトライン -

$mail->IsSMTP(); 

を、それはあなたのために動作します。

私はさまざまなサイトから多くの回答を確認して実験しましたが、上記の解決策以外の解決策はありませんでした。