0
votes

I have configured the php.ini and sendmail.ini on in XAMPP to send emails and its working fine. Now when i change the code in php to use SMTP its not working... Its using the same host, same smtpsecure, same port, same email as in XAMPP and its not working...

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=1234
[email protected]
php.ini
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
For Win32 only.
http://php.net/sendmail-from
sendmail_from = [email protected]

and my php code

<?php
$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->Port = 587;
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = '1234';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->setLanguage('pl', './vendor/phpmailer/phpmailer/language/phpmailer.lang-pl.php');
$mail->setFrom("[email protected]");
$mail->addAddress('[email protected]');     // Add a recipient // Name is optional
$mail->IsHTML(true);
$mail->Subject = "Prośba o dostęp demo";
$mail->Body = "<p>Wysłano z formularza kontaktowego na stronie bhp.xyz.pl.</p>
</p>";
if(!$mail->Send()){
    echo "\n"."Mailer Error: " . $mail->ErrorInfo;
}
else{
    echo "Message sent!";
}
?>

Errors: SERVER -> CLIENT: 220 smtp.gmail.com ESMTP f40sm329317edb.7 - gsmtp CLIENT -> SERVER: EHLO PhpStorm 2017.1 SERVER -> CLIENT: 501-5.5.4 HELO/EHLO argument "PhpStorm 2017.1" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo f40sm329317edb.7 - gsmtp SMTP ERROR: EHLO command failed: 501-5.5.4 HELO/EHLO argument "PhpStorm 2017.1" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo f40sm329317edb.7 - gsmtp CLIENT -> SERVER: HELO PhpStorm 2017.1 SERVER -> CLIENT: SMTP ERROR: HELO command failed: SMTP NOTICE: EOF caught while checking if connected SMTP Error: Could not connect to SMTP host. SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

2

2 Answers

1
votes

This is effectively a bug in PHPStorm, which I reported here.

There is an automatic workaround in the PHPMailer 6.0 branch, but you should be able to do it yourself by setting the Hostname property to something valid, for example:

$mail->Hostname = 'localhost.localdomain';

The Hostname property is the name presented in HELO/EHLO commands to the server(s) in the Host property - don't get the two confused!

0
votes

I figured this out... Too many hours spend on something like this.. I've added virtual host in XAMPP:

<VirtualHost *:80>
 ServerAdmin webmaster@localhost

 DocumentRoot "D:/xampp/htdocs/BHP"
 ServerName bhpsmart.com
 SSLEngine on
 SSLCertificateFile "conf/ssl.crt/server.crt"
 SSLCertificateKeyFile "conf/ssl.key/server.key"
 <Directory "D:/xampp/htdocs/BHP">
  Options All
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
 </Directory>

 ErrorLog logs/platforma-error.log
 LogLevel info
 CustomLog logs/platforma.log combined
</VirtualHost>

They key lines are :

SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"

Now its working properly.