<?php
$subject = "Registration Confirmation";
// The non-HTML text
$alt_body = "\r\n** CONFIDENTIAL **\r\n\r\n";
$alt_body .= "Thank you for registering.\r\n\r\n";
// HTML text
$body = "** CONFIDENTIAL **<br><br>";
$body .= "Thank you for registering.<br><br>";
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output ####################### CHANGE TO 0 FOR PRODUCTION ##############################
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = "support@example.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->SMTPSecure = 'none'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'support@example.com';
$mail->FromName = "Support";
$mail->addAddress("name@gmail.com"); // Add a recipient
$mail->addReplyTo('support@example.com', 'Support');
$mail->WordWrap = 50;
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $alt_body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
2015-04-10 18:46:57 Connection: opening to smtp.example.com:587, t=300, opt=array ( )
Error '2'
occurred in script '/folders/includes/class.smtp.php' on line 254:
stream_socket_client(): unable to connect to smtp.example.com:587 (Connection refused)
with 'Array'
Date/Time: 10-4-2015 14:46:57
2015-04-10 18:46:57 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-10 18:46:57 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.temp exit
<?php
// In class.smtp.php ..
if ($streamok) {
$socket_context = stream_context_create($options);
//Suppress errors; connection failures are handled at a higher level
$this->smtp_conn = @stream_socket_client(
$host . ":" . $port,
$errno,
$errstr,
$timeout,
STREAM_CLIENT_CONNECT,
$socket_context
); // <<<<<<<<<<<<< LINE 254 IN class.smtp.php <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
* PHPMailer - PHP email creation and transport class.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* PHPMailer - PHP email creation and transport class.
* @package PHPMailer
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
*/
class PHPMailer
{
/**
* The PHPMailer Version number.
* @type string
*/
public $Version = '5.2.9';
* PHPMailer RFC821 SMTP email transport class.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* PHPMailer RFC821 SMTP email transport class.
* Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
* @package PHPMailer
* @author Chris Ryan
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class SMTP
{
/**
* The PHPMailer SMTP version number.
* @type string
*/
const VERSION = '5.2.9';
From: https://github.com/PHPMailer/PHPMailer/blob/master/changelog.md
Version 5.2.9 (Sept 25th 2014)
Important: The autoloader is no longer autoloaded by the PHPMailer class
From: https://www.drupal.org/node/2381475
Here are the release note from PHPMailer library 5.2.9 (latest version):
The autoloader is no longer autoloaded automatically, and the PHPMailer class does not require the SMTP class explicitly, so you must either load the autoloader yourself (as all the docs and examples have done for the last year), or load the SMTP class yourself. This fixes the inability to substitute your own SMTP subclass, and also improves interoperability with other autoloaders.
It means that the SMTP class is not loaded anymore, which make the module crash when trying to send an email.
<?php
// phpmailer test script
require 'includes/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.example.com'; // sets the SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example@example.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'support@example.com';
$mail->FromName = 'Support';
$mail->addAddress('user@gmail.com', 'User'); // Add a recipient
$mail->addAddress('myself@gmail.com'); // Name is optional
$mail->addReplyTo('support@example.com', 'Support');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
2015-04-12 17:11:13 Connection: opening to smtp.example.com:587, t=300, opt=array ( ) 2015-04-12 17:11:13 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-12 17:11:13 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.
<?php
/**
* This uses the SMTP class alone to check that a connection can be made to an SMTP server,
* authenticate, then disconnect
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/GMT-7'); // Vancouver, BC
require '../PHPMailerAutoload.php';
//Create a new SMTP instance
$smtp = new SMTP;
//Enable connection-level debug output
$smtp->do_debug = SMTP::DEBUG_CONNECTION;
try {
//Connect to an SMTP server
if ($smtp->connect('smtp.example.com', 587)) { // was 25 timed out 587 no delay Both: 'connect failed'
//Say hello
if ($smtp->hello('smtp.example.com')) { //Put your host name in here
//Authenticate
if ($smtp->authenticate('username', 'password')) {
echo "Connected ok!";
} else {
throw new Exception('Authentication failed: ' . $smtp->getLastReply());
}
} else {
throw new Exception('HELO failed: '. $smtp->getLastReply());
}
} else {
throw new Exception('Connect failed');
}
} catch (Exception $e) {
echo 'SMTP error: '. $e->getMessage(), "\n";
}
//Whatever happened, close the connection.
$smtp->quit(true);
?>
2015-04-12 16:50:09 Connection: opening to smtp.example.com:587, t=30, opt=array ( ) 2015-04-12 16:50:09 SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP error: Connect failed
2015-04-12 21:22:47 Connection: opening to smtp.gmail.com:587, t=300, opt=array ( ) 2015-04-12 21:22:47 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-12 21:22:47 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.
2015-04-12 21:28:54 Connection: opening to smtp.gmail.com:465, t=300, opt=array ( ) 2015-04-12 21:28:54 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-12 21:28:54 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.
Telnet:openssl:
OpenSSL support enabled
OpenSSL Library Version OpenSSL 1.0.1e 11 Feb 2013
OpenSSL Header Version OpenSSL 1.0.1e 11 Feb 2013
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = On
; Define the anonymous ftp password (your email address). PHP's default setting
; for this is empty.
; http://php.net/from
;from="john@doe.com"
; Define the User-Agent string. PHP's default setting for this is empty.
; http://php.net/user-agent
;user_agent="PHP"
; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = 60
; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; http://php.net/auto-detect-line-endings
;auto_detect_line_endings = Off
Warning: fsockopen(): unable to connect to tcp://smtp.example.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 7
var_dump(ini_get('disable_functions'));
so that the script was:
<?php
$fp = fsockopen('tcp://smtp.gmail.com', 587, $errno, $errstr, 10);
echo fgets($fp, 128);
var_dump(ini_get('disable_functions'));
//var_dump(ini_get('safe_mode')); //No longer in PHP as of 5.4
//var_dump(ini_get('allow_url_fopen'));
//var_dump(stream_get_transports());
var_dump($fp, $errno, $errstr);
fclose($fp);
?>
and got:Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 string(0) "" bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11
Then I removed 'disable_functions' replacing with safe_mode, and got:Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 string(0) "" bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11
Similarly, allow_url_fopen:Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 string(1) "1" bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11
And stream_get_transports():Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 array(8) { [0]=> string(3) "tcp" [1]=> string(3) "udp" [2]=> string(4) "unix" [3]=> string(3) "udg" [4]=> string(3) "ssl" [5]=> string(5) "sslv3" [6]=> string(5) "sslv2" [7]=> string(3) "tls" } bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11
var_dump(ini_get('disable_functions'));
=> string(0) ""
var_dump(ini_get('safe_mode')); //No longer in PHP as of 5.4
=> string(0) ""
var_dump(ini_get('allow_url_fopen'));
=> string(1) "1"
var_dump(stream_get_transports());
=> array(8) { [0]=> string(3) "tcp" [1]=> string(3) "udp" [2]=> string(4) "unix" [3]=> string(3) "udg" [4]=> string(3) "ssl" [5]=> string(5) "sslv3" [6]=> string(5) "sslv2" [7]=> string(3) "tls" }