3

Hi all i am new in php and html and facing issue: SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. but working fine in local xampp and coming error in server. code below:

<?php
    $name = $_POST['name'];
    $contact = $_POST['contact'];
    $email = $_POST['email'];
    $company = $_POST['company'];
    $message = $_POST['message'];
    $msg= " <strong>Name:</strong> $name <br /> <strong>Contact:</strong> $contact <br /> <strong>Email:</strong> $email <br /><strong>Company:</strong> $company <br /><strong>Message:</strong> $message";
    require_once('mailer/class.phpmailer.php');
    $mail             = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host       = "smtp.gmail.com";
    $mail->SMTPDebug  = 0;               
    $mail->SMTPSecure = "ssl";
    $mail->SMTPAuth   = true;                  
    $mail->Host       = "smtp.gmail.com";
    $mail->Port       = 465;                    
    //$mail->Username   = "[email protected]";
    //$mail->Password   = "gmail pass";    
    //$mail->SetFrom('[email protected]', 'Pankaj U');
    $mail->SetFrom($email);
    $mail->AddReplyTo($email);
    $mail->Subject    = "Enquiry from Website";
    $mail->MsgHTML($msg);
    $address = "[email protected]";
    $mail->AddAddress($address, $name);
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      header('Location: thanks.html');
    }
?>
2
  • you need to check your firewall Commented Oct 20, 2015 at 8:03
  • but working fine in local server? Commented Oct 20, 2015 at 8:06

1 Answer 1

4
$mail->SMTPSecure = "tls";
$mail->Port       = 587; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.