2017-12-07 10 views
0

私はPHPのメーラーでのSMTP接続に関する問題に直面していますが、ここに私のコード実際にメーラーエラー:SMTP connect()に失敗しましたか?

<?php 
// Import PHPMailer classes into the global namespace 
// These must be at the top of your script, not inside a function 

//Load composer's autoloader 
use PHPMailer\PHPMailer\PHPMailer; 
use PHPMailer\PHPMailer\SMTP; 
use PHPMailer\PHPMailer\Exception; 

require 'Exception.php'; 
require 'PHPMailer.php'; 
require 'SMTP.php'; 
$mail = new PHPMailer(true);        // Passing `true` enables exceptions 
try { 
    //Server settings 

    $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 = 'password';       // SMTP password 
    $mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = 465;         // TCP port to connect to 

    //Recipients 
    $mail->setFrom('[email protected]', 'mine'); 
    $mail->addAddress('[email protected]', 'mine');  // Add a recipient 
    $mail->addReplyTo('[email protected]', 'mine'); 
    //Content 
    $mail->isHTML(true);         // Set email format to HTML 
    $mail->Subject = $_POST['name']; 
    $mail->Body = $_POST['mail']."<br>" .$_POST['phn']."<br>".$_POST['des']; 
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

    $mail->send(); 
    echo 'Message has been sent';echo "<br>";`enter code here` 
    echo "<a href=index.html>Go Back"; 
} catch (Exception $e) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} 

?> 

このコードは完璧に実行していたと私はメールを得ていたが、現在はそれが仕事とメーラーエラーを言っていないです:SMTP接続します()これはエラーとして失敗しました。助けて !!!

おかげで...

+0

あなたは、ポート465が開いていることをホストに確認することができますか? –

+0

ポート465を開いてSMTPとして割り当てたことを除いて、ポート587を使用してみてください。 –

+0

ポート465のチェック方法は開いているかどうか? – lexicn

答えて

0

は、この方法が...多分証明書が自己署名またはこのような何かされ、それを試してみてください。

Failing that, you can allow insecure connections via the SMTPOptions property introduced in PHPMailer 5.2.10 (it's possible to do this by subclassing the SMTP class in earlier versions), though this is not recommended as it defeats much of the point of using a secure transport at all:

$mail->SMTPOptions = array(
    'ssl' => array(
     'verify_peer' => false, 
     'verify_peer_name' => false, 
     'allow_self_signed' => true 
    ) 
); 

https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

関連する問題