<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myemail@gmail.com"; // GMAIL username
$mail->Password = "******"; // GMAIL password
$mail->SetFrom('mysent@gmail.com', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "mymail@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
When I run the script on my local machine I got
CLIENT -> SMTP: EHLO localhost CLIENT -> SMTP: AUTH LOGIN CLIENT -> SMTP: cHV0aGVhLmh1b25nMjAxNEBnbWFpbC5jb20= CLIENT -> SMTP: UHV0aGVhMDEy CLIENT -> SMTP: MAIL FROM: CLIENT -> SMTP: RCPT TO: CLIENT -> SMTP: DATA CLIENT -> SMTP: Date: Mon, 17 Jun 2013 04:25:49 -0400 CLIENT -> SMTP: Return-Path: CLIENT -> SMTP: To: user2 CLIENT -> SMTP: From: PRSPS CLIENT -> SMTP: Subject: PRSPS password CLIENT -> SMTP: Message-ID: <405be3508111cd4789653ec34cdfba23@localhost> CLIENT -> SMTP: X-Priority: 3 CLIENT -> SMTP: X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/) CLIENT -> SMTP: MIME-Version: 1.0 CLIENT -> SMTP: Content-Type: multipart/alternative; CLIENT -> SMTP: boundary="b1_405be3508111cd4789653ec34cdfba23" CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23 CLIENT -> SMTP: Content-Type: text/plain; charset=iso-8859-1 CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: gdssdh CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23 CLIENT -> SMTP: Content-Type: text/html; charset=iso-8859-1 CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: gdssdh CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23-- CLIENT -> SMTP: CLIENT -> SMTP: . CLIENT -> SMTP: quit Message sent!
But When I run the same script on hosting
SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)SMTP Connect() failed. Mailer Error: SMTP Connect() failed.
Do you have any idea to fix this problem?
Thanks in advance.