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 PHPMailerPHPMailerPHPMailer;
$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…
3
Answers
This is mostly due to your hosting providers firewall issues. See on below link where someone had similar issue –
https://github.com/PHPMailer/PHPMailer/issues/295
Contact your hosting provider, they will be able to help you
I’ve been using mailgun and I love it. Mailgun.com Totally free for a case like this.
As a suggestion, can you see if there’s a sendmail daemon running on your box? Maybe that will be good enough for your use case?
I tried your code with my email and token, also not work, it shows :
then i changed below two lines:
to
then, it works
hope to help you.