2
votes

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!";
}

?>

2
any errors returned?Mohammad
Check if PEAR Mail is installed on the server, if it is you can use it as alternative to PHPMailer. pear.php.net/manual/en/package.mail.mail.phpAuris
try sending it ur mail id like this and check if its wrking. if it is snot working then lets try something else $toMail = "[email protected]";rahul patel
@Mohammad error displays as SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP connect() failed.Chaitali Patil
@rahulpatel tried mail id as gmail id. But giving the same errorChaitali Patil

2 Answers

2
votes

Setting the SMTPOptions solves my problem.

 <?php
 require 'vendor/autoload.php';;
 $body = 'Hi this is test message';
 $mail             = new PHPMailer();
 $mail->IsSMTP(); // telling the class to use SMTP
 $mail->SMTPOptions = [
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true,
        ],
    ];
  $mail->Host       = "mail.domain.com"; // SMTP server            
  $mail->SMTPDebug  = 2;  
  $mail->Debugoutput = 'html';
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = ''; // Enable TLS encryption, `ssl` also accepted
  $mail->Port = 587;

  $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!";
   }
 ?>
0
votes

Change the MX record settings and check once. In the cPanel Mail section Search for MX Entry Maintenance. Then Select the related domain and Change Email Routing to Remote Mail Exchanger. Add all the google MX records as they are in your domain configuration. For more details on how to configure domain Click here

And set SMTP_SERVER as localhost like this SMTP_SERVER: localhost