php
  • smtp
  • phpmailer
  • web-development-server
  • 2015-06-17 29 views -1 likes 
    -1

    我正在嘗試爲網站製作其中一種常用的聯繫表單,以便用戶可以直接從我的網站向我發送電子郵件。PHPMailer的用戶名和密碼字段有什麼變化?

    這裏是我到目前爲止的代碼

    <html> 
    
    
    <body> 
    
    
    <?php 
    require("PHPMailer_5.2.0/class.phpmailer.php"); 
    
    $mail = new PHPMailer(); 
    $mail->IsSMTP(); 
    $mail->Mailer = 'smtp'; 
    $mail->SMTPAuth = true; 
    $mail->Host = 'smtp.gmail.com'; 
    $mail->Port = 465; 
    $mail->SMTPSecure = 'ssl'; 
    
    
    $mail->Username = "[email protected]"; 
    $mail->Password = "password"; 
    
    //$mail->IsHTML(true); // if you are going to send HTML formatted emails 
    
    $mail->From = "[email protected]"; 
    $mail->FromName = "FROM NAME"; 
    
    $mail->addAddress("[email protected]","Vik Kalkat"); 
    
    $mail->Subject = "Testing PHPMailer with localhost"; 
    $mail->Body = "Hi,<br /><br />This system is working perfectly."; 
    
    if(!$mail->Send()) 
        echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo; 
    else 
        echo "Message has been sent"; 
    
    ?> 
    
    
    </body> 
    
    
    </html> 
    

    我得到的錯誤是

    SMTP Error: Could not connect to SMTP host. Message was not sent 
    PHPMailer Error: SMTP Error: Could not connect to SMTP host. 
    

    我猜這可能是因爲我的「用戶名」和「密碼」參數可能是錯誤的,因爲我不確定用戶名和密碼是否應該去這裏。
    是我想要發送電子郵件的電子郵件帳戶的登錄信息嗎?

    +0

    嘗試'$ mail-> SMTPDebug = 1;'看到更多的錯誤輸出,通常是一個ssl問題 – RightClick

    +0

    我得到了.. SMTP - >錯誤:無法連接到服務器:因爲目標機器無法建立連接積極拒絕。 (10061) SMTP錯誤:無法連接到SMTP主機。郵件未發送 PHPMailer錯誤:SMTP錯誤:無法連接到SMTP主機。 – user3646493

    +0

    您是否嘗試過端口587上的TLS而不是465上的SSL?順便說一句,用戶名和密碼必須是你的谷歌賬號 – RightClick

    回答

    0

    你應該嘗試使用TLS一個

    這是對端口587

    變化

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

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

    另一個問題可能是您的梅勒是' smtp'而不是'郵件'

    相關問題