3
votes

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');
    }
?>
1
you need to check your firewallMinesh Patel
but working fine in local server?balajee enterprises

1 Answers

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