0
votes
<?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   = "[email protected]";  // GMAIL username
$mail->Password   = "******";            // GMAIL password

$mail->SetFrom('[email protected]', 'PRSPS');

//$mail->AddReplyTo("[email protected]', '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 = "[email protected]";
$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.

1
Do you have a firewall preventing access to port 465? Can you telnet in to 465 on smtp.google.com?Henkealg
How can we check it on the hosting?kn3l
If you have server access to the hosting (SSL access) you can use a terminal or Putty to access the server, then test a telnet connection from it. Some hosts also has firewall settings in the admin pages for the account.Henkealg
Do you have some tips for testing telnet connection ? what it can or can not ? thankskn3l
I guess the answer depends on if you have SSL terminal access to the host account or not. If you have, you should be able to run the command "telnet smtp.google.com 465" without errors.Henkealg

1 Answers

1
votes

Your hosting may have firewalled the used ports. Try using other ports (with other security) settings or contact your hoster.