I am using PHPMailer 6.2 (shared webhosting so I grabbed the latest version of the code from Github and uploaded it to my FTP. When I want to send mail without SMTP, there are no problems sending mail. When I do use SMTP (and I do need to), however, nothing happens. It kind of looks like the page won't load at all. I don't get errors or notices, so I'm at a loss what I'm doing wrong here. Using an SMTP test tool, I see that my credentials and the connection details are OK. Here's my code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__.'/PHPMailer/src/Exception.php';
require __DIR__.'/PHPMailer/src/PHPMailer.php';
require __DIR__.'/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(TRUE);
try {
$mail->setFrom("xxx", "Test");
$mail->addAddress('xxx', 'Test');
$mail->Subject = 'Bericht via de website';
$mail->Body = "hier een testbericht";
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = 'tls';
$mail->Username = 'xxx';
$mail->Password = 'xxx';
$mail->Port = 587;
$mail->send();
} catch (Exception $e) {
echo $e->errorMessage();
} catch (\Exception $e) {
echo $e->getMessage();
}
die("done");
?>
Edit: after 20 minutes of loading, the following response is generated:
2020-11-28 19:40:07 CLIENT -> SERVER: EHLO <my/e-mail rcpt domain>
2020-11-28 19:45:07 SERVER -> CLIENT:
2020-11-28 19:45:07 SMTP ERROR: EHLO command failed:
2020-11-28 19:45:07 CLIENT -> SERVER: HELO <my/e-mail rcpt domain>
2020-11-28 19:50:07 SERVER -> CLIENT:
2020-11-28 19:50:07 SMTP ERROR: HELO command failed:
2020-11-28 19:50:07 CLIENT -> SERVER: STARTTLS
2020-11-28 19:55:07 SERVER -> CLIENT:
2020-11-28 19:55:07 SMTP ERROR: STARTTLS command failed:
SMTP Error: Could not connect to SMTP host.
2020-11-28 19:55:07 CLIENT -> SERVER: QUIT
2020-11-28 20:00:07 SERVER -> CLIENT:
2020-11-28 20:00:07 SMTP ERROR: QUIT command failed:
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.```
Related
Error/SMTP Debug
I am using free Hosting
These are the errors shown in the SMTP debug,
I tried all the error rectifying method
2021-06-09 10:48:28 CLIENT -> SERVER: EHLO pro-online-grocery-store.000webhostapp.com
2021-06-09 10:48:28 CLIENT -> SERVER: STARTTLS
2021-06-09 10:48:28 CLIENT -> SERVER: EHLO pro-online-grocery-store.000webhostapp.com
2021-06-09 10:48:28 CLIENT -> SERVER: AUTH LOGIN
2021-06-09 10:48:28 CLIENT -> SERVER: [credentials hidden]
2021-06-09 10:48:28 CLIENT -> SERVER: [credentials hidden]
2021-06-09 10:48:29 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu534-5.7.14 r9miUOgrMuntYtRkI3wx89ZiLPDiYDroneH6_Ac89byfZeSU2gtMewvVSN-TnwnTEsK2X534-5.7.14 X6W1XKlpqvOKd-K2MZpowZc693zGaaoSyXDK15XQ5QE-ox79_jKysPinbpuBFaXB>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 v17sm12296941qta.77 - gsmtp
SMTP Error: Could not authenticate.
2021-06-09 10:48:29 CLIENT -> SERVER: QUIT
SMTP Error: Could not authenticate.
Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd3/353/16879353/public_html/vendor/phpmailer/phpmailer/src/SMTP.php:278) in /storage/ssd3/353/16879353/public_html/function_db.php on line 36
My PhpMailer code
I think my code is correct because it works perfectly in local host and dont know why it is not working
<?php
session_start();
require 'db.php';
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
function mailTo($to, $user, $subject, $body, $success, $error)
{
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '***************#gmail.com';
$mail->Password = '*********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('saigrocery#gmail.com', 'onlineshopping');
$mail->addAddress($to, $user);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
if ($mail->send()) {
header($success);
}
} catch (Exception $e) {
header($error);
}
}
?>
I am unable to send an email on my local server.
I used following phpmailer code to test mail sending:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 587; // SMTP port
$mail->Username = ""; // username
$mail->Password = ""; // password
$mail->SetFrom('', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "";
$mail->AddAddress($address, "Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
But I get the following error:
2020-07-06 09:20:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y7sm6517117pjy.54 - gsmtp
2020-07-06 09:20:08 CLIENT -> SERVER: EHLO localhost
2020-07-06 09:20:08 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [157.49.67.14]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2020-07-06 09:20:08 CLIENT -> SERVER: STARTTLS
2020-07-06 09:20:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2020-07-06 09:20:09 CLIENT -> SERVER: QUIT
2020-07-06 09:20:09
2020-07-06 09:20:09
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Please suggest possible solutions.
2018-03-05 18:25:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP
o5sm27821483pfh.51 - gsmtp 2018-03-05 18:25:08 CLIENT -> SERVER: EHLO
localhost 2018-03-05 18:25:08 SERVER -> CLIENT: 250-smtp.gmail.com at
your service, [43.247.156.6]250-SIZE
35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8 2018-03-05 18:25:08 CLIENT -> SERVER: STARTTLS 2018-03-05
18:25:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS SMTP Error:
Could not connect to SMTP host. 2018-03-05 18:25:09 CLIENT -> SERVER:
QUIT 2018-03-05 18:25:09 2018-03-05 18:25:09 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message
has been sent
my code is
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'girish8134#gmail.com'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('girish8134#gmail.com', 'Giri');
$mail->addAddress('girish3055#gmail.com', 'giri3055'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message bod';
$mail->AltBody = 'This is the body is';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
first try this> https://support.google.com/accounts/answer/1064203?hl=en
Disabling two step authentication.
If it doesn't work like that, you can always try and simplify some code (and try ssl - port 467):
$mail->setFrom('girish8134#gmail.com');
$mail->addAddress('girish3055#gmail.com');
Let me know if it worked.
Try this:
$mail->SMTPSecure = 'ssl'; // Use SSL encryption,
$mail->Port = 465 // change port to 465
I am trying to send an e-mail on my PHP script. Since mail() is disabled by my host, I had to use PHPMailer. I've set all the variables it needs. However I still can't send anything. I've tried a 3rd party website to test SMTP server and it worked. I've also tried to connect that SMTP server via Telnet but it gave me connection error as it did on PHP script.
I can't see anything about host in debug text. Did I set host in script with a wrong way? Lastly, host doesn't support TLS,SSL so I've set SMTPSecure to false.
$mail = new PHPMailer();
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.myhost.com';
$mail->SMTPAuth = true;
$mail->Username = 'verify#mydomain.com';
$mail->Password = 'mypass';
$mail->SMTPSecure = false;
$mail->Port = 25;
//Recipients
$mail->setFrom('verify#mydomain.com');
$mail->addAddress('recipient#test.com');
//Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
And this is the debug text:
2018-02-27 11:05:59 SERVER -> CLIENT:
2018-02-27 11:05:59 CLIENT -> SERVER: EHLO mydomain.com
2018-02-27 11:05:59 SERVER -> CLIENT:
2018-02-27 11:05:59 SMTP ERROR: EHLO command failed:
2018-02-27 11:05:59 CLIENT -> SERVER: HELO mydomain.com
2018-02-27 11:05:59 SERVER -> CLIENT:
2018-02-27 11:05:59 SMTP ERROR: HELO command failed:
SMTP Error: Could not authenticate.
2018-02-27 11:05:59 CLIENT -> SERVER: QUIT
2018-02-27 11:05:59 SERVER -> CLIENT:
2018-02-27 11:05:59 SMTP ERROR: QUIT command failed:
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I'm getting an EOF error. I'm using the basic template with a few subtractions (attachments, cc, etc) and one addition (AuthType='PLAIN').
<?php
require __DIR__ . '/vendor/autoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.zoho.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->AuthType = 'PLAIN';
$mail->Username = '*******'; // SMTP username
$mail->Password = '*******'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('*************', '*****');
$mail->addAddress('*********', '******'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'From phpmailer-test.php';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
-I've tried STMP via 465 both with this script and with telnet and gotten the same error.
-I've tested this with tls and 587 with this script (but not telent) and gotten this error.
-I'm using composer, per the Troubleshooting page's instructions.
-Script is at phillyguitarlessons.com, mail account is at *#kalegood.com (hosted by zoho.com). I don't think this would cause an error, but am not sure.
-I've tried looking through the docs (via a page search for "EOF") and found nothing.
-From my VPS, my ports should be wide-open. To zoho.com
-Opensssl is activated (confirmed via info.php)
Output (switched to debug level 2):
2016-10-03 13:47:40 SERVER -> CLIENT: 220 mx.zohomail.com SMTP Server ready October 3, 2016 6:47:40 AM PDT
2016-10-03 13:47:40 CLIENT -> SERVER: EHLO phillyguitarlessons.com
2016-10-03 13:47:40 SERVER -> CLIENT: 250-mx.zohomail.com Hello phillyguitarlessons.com (162.243.32.109 (162.243.32.109)) 250-STARTTLS 250 SIZE 53477376
2016-10-03 13:47:40 CLIENT -> SERVER: STARTTLS
2016-10-03 13:47:40 SERVER -> CLIENT: 220 Ready to start TLS.
2016-10-03 13:47:41 CLIENT -> SERVER: EHLO phillyguitarlessons.com
2016-10-03 13:47:41 SERVER -> CLIENT: 250-mx.zohomail.com Hello phillyguitarlessons.com (162.243.32.109 (162.243.32.109)) 250-AUTH LOGIN PLAIN 250 SIZE 53477376
2016-10-03 13:47:41 CLIENT -> SERVER: AUTH PLAIN
2016-10-03 13:49:46 SERVER -> CLIENT: 334
2016-10-03 13:49:46 SMTP NOTICE: EOF caught while checking if connected
2016-10-03 13:49:46 SMTP Error: Could not authenticate.
2016-10-03 13:49:46 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting