Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer: Using remote SMTP server, works under localhost, Connection refused (111) on remote server

I've got a bizarre problem here. I'm trying to use PHPMailer to send an email, through SMTP. I have a website hosted by GoDaddy and it's that SMTP account that I'm trying to use to send the mail.

  1. It works if I execute my PHP file on my localhost server.
  2. It does not work if I execute my PHP file on GoDaddy's server.

The error message I get is:

SMTP -> ERROR: Failed to connect to server: Connection refused (111)

I checked phpinfo on both localhost and the remote server. Both have smtp_port listed as 25. I'm using WAMP on my machine and the server is some form of Linux (which I know nothing about and have no idea how to administer).

Here is the code in question:

INDEX.PHP:

<?php
date_default_timezone_set('America/Los_Angeles');
include_once("phpmailer/class.phpmailer.php");

$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->Port = 25;

$mail->IsSMTP();
$mail->Host = 'smtpout.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result

$mail->ClearAddresses();
$mail->AddAddress('[email protected]', 'Receiver Name');
$mail->From = "[email protected]";
$mail->FromName = "Username";
$mail->Subject = 'Hi there';
$mail->Body = "This is a message";

if ($mail->Send()) {
    echo "Message sent!\n";
}
else {
    echo "Message failed!\n";
    print_r($mail->ErrorInfo);
}

exit();
?>
like image 375
a.real.human.being Avatar asked Feb 13 '23 20:02

a.real.human.being


1 Answers

I think you should perform two step 1) check your port as suggested on godaddy support http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account 2)use "relay-hosting.secureserver.net" as your host instead of "smtpout.secureserver.net"

GoDaddy does allow to send emails using Gmail as your SMTP, just need to get rid of the smtp.gmail.com and use their Host instead. This is my setup:

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "[email protected]";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...

Reference (see first two posts) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

like image 104
Amit Yadav Avatar answered Feb 17 '23 01:02

Amit Yadav