0

I am getting following error: SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: test@gmail.com : Called Mail() without being connected

What is problem in my code or any other problem?

My openssl is also enable

I am doing following coding:

<?php
      include("securimage/securimage.php");
      $img = new Securimage();
      $valid = $img->check($_POST['code']);

      if($valid == true) {

        require_once('class.phpmailer.php'); 

        $mail = new PHPMailer(); 
        $body="Name : ".$_POST['name']."<br>";
        $body .="Subject : ".$_POST['subject']."<br>";
        $body .="Phone : ".$_POST['phone']."<br>";
        $body .="Email : ".$_POST['email']."<br>";
        $body .=$_POST['comment']."<br>";
        $mail->IsSMTP(); 
        $mail->SMTPDebug  = 1;                 
        $mail->SMTPAuth   = true;                
        $mail->SMTPSecure = "ssl";                 
        $mail->Host= "smtp.gmail.com";     
        $mail->Port       = 465;                   
        $mail->Username   = "contactus@gmail.com";  
        $mail->Password   = "contactus"; 
        $mail->From        = $_POST['email'];          
        $mail->FromName    = $_POST['name'];

        $mail->AddReplyTo($_POST['email']);
        $mail->Subject    = "Contact Us";
        $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; 
        $mail->MsgHTML($body);
        $mail->AddAddress('niyati@ngplweb.com', 'Niyati'); 

        if(!$mail->Send()) 
        {
              setcookie("msg","Error.",time()+5);
              header("location:contactus.php");
        } 
        else 
        {
               setcookie("msg","Thank you.We will get back to you soon......",time()+5);
               header("location:contactus.php");
         }
       } 
       else 
       {
               setcookie("msg","Incorrect Captcha.",time()+5);
               header("location:contactus.php");
        } 
        ?>
4

2 回答 2

2

您的密码分配不正确。这可能是您的连接不起作用的原因。

 mail->Password = "contactus"; 
^---

应改为:

$mail->Password = "contactus"; 
于 2013-11-14T10:28:52.030 回答
1

“SMTP -> 错误:无法连接到服务器:连接超时(110)以下发件人地址失败:test@gmail.com:调用邮件()但未连接”

这是因为

    $mail->Username   = "contactus@gmail.com";  
    $mail->Password   = "contactus"; 

不是有效的。尝试使用一些有效的用户名和密码,我认为一切都会好起来的。有效我的意思是真实的“gmail id”的真实用户名和密码。

于 2013-11-14T11:03:25.370 回答