简体   繁体   中英

PHPMAILER Mailer Error: SMTP connect() failed (No Access to Php.ini)

Good Afternoon,

I've been working on Phpmailer for a couple days and can't get around these SMTP Connect failed errors. I've disabled my firewall and have double and triple checked that my username and password are all correct. I can't access my php.ini file because my server is cloud based (Rackspace). I contacted rackspace and they told me to access my .htaccess file. I however can't find any info on what to add to the .htaccess file to make phpmailer not have an SMTP connect failed error. Code and error reporting is below. Any and all info is appreciated.

PS I also have looked in my php_errors.log file and there are no phpmailer errors in there anywhere!

include("../phpmailer/class.phpmailer.php");
include("../phpmailer/PHPMailerAutoload.php");
include("../phpmailer/class.smtp.php");

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->CharSet = 'utf-8';
$mail->ContentType = 'text/html';
$mail->SMTPDebug = 2;

$mail->SMTPAuth   = true;

$mail->SMTPSecure = "ssl";
$mail->Host       = "secure.emailsrvr.com";
$mail->Port       = 465;
$mail->Username   = "xxx@website.com";
$mail->Password   = "password";

$mail->From       = "xxx@website.com";
$mail->FromName   = "xxx";

$mail->AddAddress('xxx@website.com', 'First Name');

$mail->IsHTML(true); // send as HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is a plain-text message body';
$mail->WordWrap   = 80; // set word wrap

$mail->msgHTML(file_get_contents('..contents.htm'), dirname(__FILE__));

//Attach an image file
$mail->addAttachment('');

// HTML body
$body  = "Hello";

if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;

}else{

    echo "Message sent!";
}

Error1:

2014-12-08 17:35:42 Could not access file:
2014-12-08 17:36:03 SMTP ERROR: Failed to connect to server: Connection timed out (110)
2014-12-08 17:36:03 SMTP connect() failed. Mailer Error: SMTP connect() failed.

Error2:

2014-12-08 17:38:09 Could not access file: 
2014-12-08 17:38:10 SERVER -> CLIENT: 220 smtp17.relay.dfw1a.emailsrvr.com ESMTP - VA Code Section 18.2-152.3:1 forbids use of this system for unsolicited bulk electronic mail (Spam) 
2014-12-08 17:38:10 CLIENT -> SERVER: EHLO everyhome.com 
2014-12-08 17:38:10 SERVER -> CLIENT: 250-smtp17.relay.dfw1a.emailsrvr.com 250-SIZE 75000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250 ENHANCEDSTATUSCODES 
2014-12-08 17:38:10 CLIENT -> SERVER: AUTH LOGIN 
2014-12-08 17:38:10 SERVER -> CLIENT: 334 VXNlcm5hbWU6 
2014-12-08 17:38:10 CLIENT -> SERVER: cGF1bC5oZWNrQGV2ZXJ5aG9tZS5jb20= 
2014-12-08 17:38:10 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 
2014-12-08 17:38:10 CLIENT -> SERVER: S2ltYmVybHkxMTU= 
2014-12-08 17:38:11 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6 
2014-12-08 17:38:11 SMTP ERROR: Password command failed: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6 
2014-12-08 17:38:11 CLIENT -> SERVER: QUIT 
2014-12-08 17:38:11 SERVER -> CLIENT: 221 2.0.0 Bye 
2014-12-08 17:38:11 SMTP connect() failed. Mailer Error: SMTP connect() failed.

Typos:

$mail->msgHTML(file_get_contents('..contents.htm'), dirname(__FILE__));
                                    ^--- missing /?

unless you really do have a "double-hidden" file named "..contents.htm".

As for the smtp error - it timed out. some secure.emailsrvr.com:465 is firewalled/unreachable from your php server. Since that's not a programming problem, we can't really help you - you'll have to figure out where/how the data packets are getting dropped into the bitbucket.

my php.ini file because my server is cloud based (Rackspace). I contacted rackspace and they told me to access my .htaccess file.?

all you have in your php.ini file is the sendmail config, and you don't have to do anything with .htaccess, that's only if you're going to add things on there as you would on a php.ini file.

you need to look at the maillog. issue

tailf /var/log/maillog

if you're on the command line to get better debugging message.


this would be better if you enabled additional error log

require_once '../class.phpmailer.php';

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

try {
    $mail->AddReplyTo('name@yourdomain.com', 'First Last');
    //additional mail related code 

} catch (phpmailerException $e) {
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
    echo $e->getMessage(); //Boring error messages from anything else!
}

This does look like a straightforward authentication failure, so please double check your username and password. I suggest starting with one of the examples provided with PHPMailer - this looks like it's based on something pretty old, so also make sure you have latest PHPMailer from github.

Cut down your code to the absolute minimum in order to remove sources of error - for example just set Body directly, don't call msgHTML , don't load external content, don't add attachments - just cut out everything that's not strictly necessary.

Try connecting using 'tls' on port 587, and you could give AuthType = 'PLAIN' a go too. Also confirm that the EHLO response matches the server that you asked to connect to, in case you are being transparently redirected by your ISP.

Checking DNS and network issues is also covered in the PHPMailer docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM