I'm new to PHPMailer, and I just downloaded it with Composer and coded this as index.php
:
<?php
require_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;
$m->Host = 'smtp.mail.yahoo.com';
$m->Username = '[email protected]';
$m->Password = 'MY PASSWORD';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->IsHTML(true);
$m->SetFrom('[email protected]');
$m->FromName = 'Pouya Vaghefi';
$m->addReplyTo('[email protected]','Pouya Vey');
$m->addAddress('[email protected]','Pouya Vey');
//$m->addCC('alex@phpacademy','Alex Garret');
//$m->addBCC('alex@phpacademy','Alex Garret');
$m->CharSet = "UTF-8";
$m->Subject = 'Here is an email';
$m->msgHTML("convert HTML into a basic plain-text alternative body");
$m->Body = 'This is the body of an email';
$m->AltBody = 'This is the body of an email';
if (!$m->send()) {
echo "Mailer Error: " . $m->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Then I uploaded it to my site (my site does not use ssl) which is using cPanel and tried to load the page but I got this as error:
2018-04-19 10:03:46 SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP connect() failed. /wiki/Troubleshooting Mailer Error: SMTP connect() failed.
I also read the related questions to this problem and changed the port from 465 to 587 (with tls), 25 and 26 but couldn't solve the problem yet.
So can you please help me with this error, cause I really don't know what to do!
Thanks...