Jump to content

Email using PHPmailer to gmail giving SMTP Error?


elearnindia

Recommended Posts

I am trying to send email using PHPmailer with google SMTP server, it is giving an SMTP error(SMTP Error:could not connect to SMTP host),I am showing the code below:-

 

<?
if(isset($_POST['email']))
{
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$phone = $_POST['phone']; // not required
$comments = $_POST['comments']; // required


$email_message .= "First Name: ".$first_name."\n\n";
$email_message .= "Email: ".$email_from."\n\n";
$email_message .= "Telephone: ".$phone."\n\n";
$email_message .= "Comments: ".$comments."\n";

require_once('PHPMailer_v5.1/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();  // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Username = "username"; // SMTP username
$mail->Password = "password"; // SMTP password

$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host     = "smtp.gmail.com"; // sets GMail as the SMTP  server
$mail->Port = 465;  // set the SMTP port for the GMAIL server

$mail->From = $email_from;
$mail->FromName = $first_name;
$mail->SetFrom($email_from, $first_name);
$mail->AddReplyTo($email_from, $first_name);
$mail->AddAddress("[email protected]",$first_name);
$mail->AddCC("[email protected]",$first_name);
$mail->AddBCC("[email protected]",$first_name);													 
$mail->Subject  = "Sree Vizag Marketing-Tiles Enquiry";
$mail->Body     = $email_message;
$mail->WordWrap = 200;

if(!$mail->Send()) 
    {
       echo "<script>alert('Appears to be Server Problem! Please contact again!');window.location='contact.html';</script>";
    }
else
    {
	echo "<script>alert('Email sent,get back to you soon!');window.location='index.html';</script>";
    }

}

?>

 

I have also used:-

 

<?
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->Port = 587;  // set the SMTP port for the GMAIL server
?>

 

It is also giving the same SMTP error

 

Any solution to this will be gladly appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.