I had my website on a dummy server and everything worked great! I transfer my hosting over to GoDaddy and when i send myself an email to check if it works it throws this error:
SMTP -> ERROR: Failed to connect to server: Connection refused (111) The following From address failed: root@localhost : Called Mail() without being connected Mailer Error: The following From address failed: root@localhost : Called Mail() without being connected
As I said it worked on my old host and I already did the necessary stuff on gmail end and my credentials are 100% correct. but not my new 1 do I have to configure the php.ini file?
require_once('includes/class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "user@gmail.com";
$mail->Password = "password";
$mail->Subject = "Sponsorship enquiry";
$mail->Body = "<p>Sponsorship form details:</p>";
$mail->Body .= "<p>name: ".$name."</p>";
$mail->Body .= "<p>email: ".$email."</p>";
$mail->Body .= "<p>sport: ".$sport."</p>";
$mail->Body .= "<p>message: ".$message."</p>";
$mail->AddAddress("exeuity@gmail.com");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
$_SESSION['success'] = "Email successfully sent AIM will be in contact with you shortly!";
header("location:athletes.php");
exit();
}
Firstly, update your PHPMailer - your code is based on an old example.
You should also read the troubleshooting docs.
I can see you're not setting a 'from' address, so it's defaulting to root@localhost
, and that may be why you're being rejected as that's not a routable address from the outside world, so you should call $mail->setFrom()
with sensible values.
GoDaddy is notorious for blocking or rerouting outbound email, so check that you really are talking to gmail - verify the SSL certificate you get when connecting via TLS.