PHPMailer: using a remote SMTP server runs under the local host, connection rejected (111) on the remote server

I have a strange problem here. I am trying to use PHPMailer to send email through SMTP. I have a site hosted by GoDaddy and this is an SMTP account that I am trying to use to send mail.

  • It works if I execute my PHP file on my local server.
  • This does not work if I run my PHP file on a GoDaddy server.

The error message I get is:

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

I checked phpinfoon both localhost and the remote server. Both have smtp_portlisted as 25. I use WAMP on my machine, and the server is some form of Linux (which I know nothing about and don’t know how to manage).

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 = 'username@site.com';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result

$mail->ClearAddresses();
$mail->AddAddress('receiver@hotmail.com', 'Receiver Name');
$mail->From = "username@site.com";
$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();
?>
+4
2

, 1) , godaddy http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account 2) "relay-hosting.secureserver.net" "smtpout.secureserver.net"

GoDaddy Gmail SMTP, smtp.gmail.com . :

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account@gmail.com";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...

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

+5

, 25,465,587. GoDaddy:

$mail->isSMTP(); 
$mail->Host = localhost; 
$mail->SMTPAuth = true;
$mail->Username = 'example@gmail.com';
$mail->Password = 'password';

//$mail->SMTPSecure = 'tls'; 
//$mail->Port = 587;

:

$mail->isSMTP(); 
$mail->Host = localhost; 
$mail->SMTPAuth = true;
$mail->Username = 'example@yourdomain.com';
$mail->Password = 'password';

//$mail->SMTPSecure = 'tls'; 
//$mail->Port = 587;
+2

Source: https://habr.com/ru/post/1526093/


All Articles