elearnindia Posted July 23, 2010 Share Posted July 23, 2010 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. Link to comment https://forums.phpfreaks.com/topic/208670-email-using-phpmailer-to-gmail-giving-smtp-error/ Share on other sites More sharing options...
cags Posted July 23, 2010 Share Posted July 23, 2010 You may find this tutorial I was working on awhile ago helpful... Link to comment https://forums.phpfreaks.com/topic/208670-email-using-phpmailer-to-gmail-giving-smtp-error/#findComment-1090224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.