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("sureshbaburavilla@gmail.com",$first_name); $mail->AddCC("sridhar.425@gmail.com",$first_name); $mail->AddBCC("srinivasvar@gmail.com",$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>"; } } ?> PHP: I have also used:- <? $mail->SMTPSecure = "tls"; // sets the prefix to the server $mail->Port = 587; // set the SMTP port for the GMAIL server ?> PHP: It is also giving the same SMTP error Any solution to this will be gladly appreciated.
Hello Deacalion,Code running on local server sending email perfectly, but on a web host it is giving SMTP error.
Google's mail servers require you to use SSL, they won't accept plaintext connections. If your web host doesn't have open SSL available to you, I'd consider switching unless they add it. If you do indeed have it installed, it would show in phpinfo()