2017-02-15 28 views
2

は、ここに私のファイル、コンタクトform.php(コード)SMTPエラー:SMTPホストに接続できませんでした。 SMTPホストに接続できませんでした:phpmailerのエラー

<?php 
if(isset($_POST['submit'])) 
{ 

$message= 
'Full Name: '.$_POST['fullname'].'<br /> 
Subject: '.$_POST['subject'].'<br /> 
Phone: '.$_POST['phone'].'<br /> 
Email: '.$_POST['emailid'].'<br /> 
Comments: '.$_POST['comments'].' 
'; 
    require "phpmailer/class.phpmailer.php"; //include phpmailer class 

    // Instantiate Class 
    $mail = new PHPMailer(); 

    // Set up SMTP 
    $mail->IsSMTP();    // Sets up a SMTP connection 
    $mail->SMTPAuth = true;   // Connection with the SMTP does require authorization  
    $mail->SMTPSecure = "ssl";  // Connect using a TLS connection 
    $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address 
    $mail->Port = 465; //Gmail SMTP port 
    $mail->Encoding = '7bit'; 

    // Authentication 
    $mail->Username = "[email protected]"; // Your full Gmail address 
    $mail->Password = "yourpassword"; // Your Gmail password 

    // Compose 
    $mail->SetFrom($_POST['emailid'], $_POST['fullname']); 
    $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']); 
    $mail->Subject = "New Contact Form Enquiry";  // Subject (which isn't required) 
    $mail->MsgHTML($message); 

    // Send To 
    $mail->AddAddress("[email protected]", "Recipient Name"); // Where to send it - Recipient 
    $result = $mail->Send();  // Send! 
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';  
    unset($mail); 

} 
?> 
<html> 
<head> 
    <title>Contact Form</title> 
</head> 
<body> 

     <div style="margin: 100px auto 0;width: 300px;"> 
      <h3>Contact Form</h3> 
      <form name="form1" id="form1" action="" method="post"> 
        <fieldset> 
         <input type="text" name="fullname" placeholder="Full Name" /> 
         <br /> 
         <input type="text" name="subject" placeholder="Subject" /> 
         <br /> 
         <input type="text" name="phone" placeholder="Phone" /> 
         <br /> 
         <input type="text" name="emailid" placeholder="Email" /> 
         <br /> 
         <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> 
         <br /> 
         <input type="submit" name="submit" value="Send" /> 
        </fieldset> 
      </form> 
      <p><?php if(!empty($message)) echo $message; ?></p> 
     </div> 

</body> 
</html> 

それはこのエラー、 SMTPエラーが表示されます。

この質問はここで聞かれますが、何も私のために働いていないことを知っています 私はここに与えられたすべての先のトリックを試してみました。エラーnは私のコーディングがどこにある 正確な...

+0

のためにTLSとポート587を使用してくださいは、サードパーティのSMTPホストを接続するためにあなたをブロック? – AkiEru

+0

あなたはこれらの質問をすべて読んでいますが、PHPMailerの古くて脆弱なバージョンを実行しています。あなたのコードは古くなった例に基づいており、このテーマに関するすべての質問からリンクされたドキュメントは読んでいません。感心しない。 – Synchro

答えて

1

この

ポート25、465、または587 SSL/TLSオプションに応じて、以下のポイントとimplemetをお読みください。 静的IPアドレスは1つ以上必要です。 ダイナミックIPは

ポートを許可

ポート465(SSLが必要) ポート587は、(TLSが必要)25 TLSは ダイナミックIPは メールのみGmailやG Suiteのユーザーに送信することができます許可は必要ありません

ref: - here

この行にコードを貼り付けて、正確なエラーを確認してください。再びSMTPエラーが発生した場合は、上記の手順に従います。

参考: - here

1

ホスティングポート587か、WebでTLSを試してみてくださいGmailの

Set up SMTP 
$mail->IsSMTP();    // Sets up a SMTP connection 
$mail->SMTPAuth = true;   // Connection with the SMTP does require authorization  
$mail->SMTPSecure = "tls";  // Connect using a TLS connection 
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address 
$mail->Port = 587; //Gmail SMTP port 
$mail->Encoding = '7bit'; 
関連する問題