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 = '';
$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();
?>