I have using phpmailer(smtp) for sending email. My website is hosted on Godaddy. I have read that phpmailer is not working with Godaddy. So tried multiple solutions to send email. But nothing worked. Error message shows SMTP -> ERROR: Failed to connect to server: Connection refused (111)SMTP Connect() failed.
adding here code, help to resolve issue.
<?php
require 'vendor/autoload.php';;
$body = 'Hi this is test message';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "relay-hosting.secureserver.net"; // SMTP server
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // SMTP account username
$mail->Password = "*****";
$mail->SetFrom('[email protected]', 'Web developer');
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>