0

I have a mail delivering script running on various pages in my website for localhost XAMPP. It was working fine till last evening and as I started today again any page having phpmailer script gives error as

SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed.

I haven't changed anything into the local server configuration and my GMAIL credentials but unable to figure out possibly what has gone wrong into the SMTP settings so that this error is coming up. I have done all my settings neatly for this setup and as I said it was working well till last evening.

<?php
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$subject = "Test Mail using PHP mailer";
$content = "<b>This is a test mail using PHP mailer class.</b>";

$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port     = 465; 
$mail->Username = "emailsender@email.com";
$mail->Password = "*******";
$mail->Host     = "ssl://smtp.gmail.com";
$mail->Mailer   = "smtp";
$mail->SetFrom("emailsender@email.com", "");
$mail->AddAddress("emailreceiver@email.com");
$mail->Subject = $subject;
$mail->WordWrap   = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);

if(!$mail->Send()) 
    echo "Problem on sending mail";
else 
echo "Mail sent";
?>

I am just unable to find out any possible reason for this . Any help or advice will be appreciated.

Anand
  • 33
  • 1
  • 9
  • Possible duplicate of [How to configure XAMPP to send mail from localhost?](https://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost) – Bilal Ahmed Dec 05 '17 at 06:00
  • @BilalAhmed I have made all those settings very prior and it was running safe and sound for months now. – Anand Dec 05 '17 at 06:03
  • are you trying to send email form local or live (domain)? – Bilal Ahmed Dec 05 '17 at 06:09
  • if you send from domain then check your domain email configuration and also send testing email from domain (cpanel) – Bilal Ahmed Dec 05 '17 at 06:10
  • @BilalAhmed I am sending it from local server XAMPP – Anand Dec 05 '17 at 06:13
  • have you configure `sendmail.ini` and `php.ini`? also share php.ini setting and sendmail.ini setting – Bilal Ahmed Dec 05 '17 at 06:15
  • I am using PHPMailer for this. And this was working well since moths. Why do I need to change sendmail.ini – Anand Dec 05 '17 at 06:16
  • ooohh.. i see a lot of issues in past 24 hour's about PHPMailer. sample reference https://stackoverflow.com/questions/47647121/sending-mail-to-both-sender-and-receiver-using-phpmailer – Bilal Ahmed Dec 05 '17 at 06:18
  • i think you should post issues on https://github.com/PHPMailer/PHPMailer this link. and i am configure xamp+PHPMailer on local to analyze the issues – Bilal Ahmed Dec 05 '17 at 06:21
  • Yeah thanks. Let me know if something comes up. – Anand Dec 05 '17 at 06:24
  • ok............. – Bilal Ahmed Dec 05 '17 at 06:25
  • @Synchro Please take a look. – Anand Dec 05 '17 at 07:12
  • I can tell that you're using a very old version of PHPMailer. [Get the latest](https://github.com/PHPMailer/PHPMailer). – Synchro Dec 05 '17 at 07:21
  • Where is the download for this available? And even though I am using old one then how can it become obsolete as it stops working. @Synchro – Anand Dec 05 '17 at 07:34
  • I provided the link to the page where you can download it, but I'd recommend you use composer anyway. It's most likely breaking because your ISP changed its policy on outbound SMTP. – Synchro Dec 05 '17 at 07:37
  • I downloaded the latest version. But the folder structure and files to be included are confusing. Can you shed some light on this whole. @Synchro – Anand Dec 05 '17 at 07:39
  • You'll find info about how to load PHPMailer in the [README](https://github.com/PHPMailer/PHPMailer/blob/master/README.md) supplied with PHPMailer, and also in the [upgrading doc](https://github.com/PHPMailer/PHPMailer/blob/master/UPGRADING.md). Base your code on the examples provided on Github, not the long-obsolete one you've used. – Synchro Dec 05 '17 at 07:42
  • How to include vendor/composer ?? I can't find any folder into the new downloaded phpmailer. @Synchro – Anand Dec 05 '17 at 07:49
  • Read the docs. It tells you what you need. – Synchro Dec 05 '17 at 07:49
  • Ok. But as you suspected that " ISP changed its policy on outbound SMTP." for me I wanted to know how this new PHPMailer is going to help if its due to ISP?? @Synchro – Anand Dec 05 '17 at 07:53
  • It may not - but it fixes many other bugs you've not encountered yet, and it provides more feedback on errors. – Synchro Dec 05 '17 at 08:14
  • I am still unable to figure out which version to download with list of all files in it. Can you provide me link that has direct download option. In GIT the list shows different files and the folder contains some other files. Highly confusing as I haven't dealt with GIT yet. @Synchro – Anand Dec 05 '17 at 08:19
  • There's a big green "Clone or download" button; click that and select "Download ZIP". – Synchro Dec 05 '17 at 08:22

1 Answers1

1

PHPMailer 6.0.2

Download: https://github.com/PHPMailer/PHPMailer/archive/master.zip

and use the code

https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

and insert code:

$mail->SMTPOptions = array ( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));

========================================================================

周靖傑
  • 11
  • 2