0
votes

I want to send mail using phpmailer. I have uploaded my phpmailer files on my Godaddy server. The below code is running in my localhost but not on my server.

2019-02-03 16:54:12 SMTP ERROR: Failed to connect to server: Connection refused (111)

The below is the code for php

<?php
include_once('PHPMailer/src/PHPMailer.php');
include_once('PHPMailer/src/SMTP.php');

$mail = new PHPMailer\PHPMailer\PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587,465
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SetFrom("[email protected]");
$mail->Subject = "Test mail";
$mail->Body = "Hello World";
$mail->AddAddress("[email protected]");
if($mail->Send()) {
    echo "Message has been sent";
}
?>
1
Search before you post. This has been answered many times before, and is explicitly covered in the PHPMailer troubleshooting guide. GoDaddy blocks outbound SMTP. You’re also using an obsolete version of PHPMailer. Upgrade it.Synchro
I have refered to similar questions but didnt find the solutionmukesh behwal
2019-02-03 20:03:22 CLIENT -> SERVER: xyz.com 2019-02-03 20:03:22 CLIENT -> SERVER: STARTTLS now this is commingmukesh behwal

1 Answers

0
votes
use PHPMailer\PHPMailer\PHPMailer; <-- make sure these are not in a function
use PHPMailer\PHPMailer\Exception;

require 'path/src/Exception.php';
require 'path/src/PHPMailer.php';
require 'path/src/SMTP.php';

Use tls and not ssl it can be buggy

$mail->SMTPSecure = "tls";
$mail->Port = 587;

Check out my answer here this will tell you everything you need to know to connect to gmail with phpmailer