Apologies for adding to the collection of PHPMailer / Gmail question. I've read them all, and still can't get this to work. First the error message:
2015-03-25 16:22:44 Connection: opening 2015-03-25 16:22:54 SMTP
ERROR: Failed to connect to server: A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond. (10060) SMTP connect() failed. Message was not
sent. Mailer error: SMTP connect() failed.
This code is the same that I have used many times to successfully send emails from a secureserver.net account, so I'm pretty confident that the script is solid. The problem must be in the gmail settings that I am trying to use(?).
try {
$mail = new PHPMailer(true);
$mail->IsSMTP(); // Using SMTP.
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 2; // Enables SMTP debug information - SHOULD NOT be active on production servers!
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = 'true'; // Enables SMTP authentication.
$mail->Host = "smtp.gmail.com"; // SMTP server host.
$mail->Port = 587; // Setting the SMTP port for the GMAIL server.
$mail->Username = "XXXXXXXXXX#gmail.com"; // SMTP account username (GMail email address).
$mail->Password = "XXXXXXXXXX"; // SMTP account password.
$mail->AddReplyTo('XXXXXXXXXX#gmail.com', 'me'); // Use this to avoid emails being classified as spam - SHOULD match the GMail email!
$mail->AddAddress('someone.else#gmail.com', 'Someone Else'); // Recipient email / name.
$mail->SetFrom('XXXXXXXXXX#gmail.com', 'me'); // Sender - SHOULD match the GMail email.
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->Body = 'Test Body';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
// $mail->MsgHTML($message);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
I've also tried port 465/ssl (and even 25, although this almost certainly won't work). I have verified with telnet that I can reach port 587:
telnet smtp.gmail.com 587 Trying 2607:f8b0:4001:c11::6c... Connected
to gmail-smtp-msa.l.google.com. Escape character is '^]'. 220
mx.google.com ESMTP f1sm1137441igt.14 - gsmtp
What am I missing? I've been over this for hours, and I don't see anything wrong. Thanks!
Have you checked the troubleshooting guide?
Use SMTPDebug = 4 for debugging low-level connection (as opposed to SMTP) problems.
Are you sure you're using latest PHPMailer? Your code looks like it's from an old example.
It would be good to eliminate PHPMailer from the test, as I suspect your problem is lower level. Write a simple script that just does an fsockopen to port 587 and reads from it, like this:
<?php
$fp = fsockopen('tcp://smtp.gmail.com', 587, $errno, $errstr, 10);
echo fgets($fp, 128);
fclose($fp);
If that works, you will see something like 220 mx.google.com ESMTP eo1sm5152802wib.16 - gsmtp from that.
If that doesn't work, suspect things like php.ini settings, disabled functions, missing extensions etc.
Related
Does anyone know the correct setting for using PHPMailer with AOL. The code below worked with outlook.com but aol.com keeps refusing it. The code is as follows;
<?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(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.aol.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxxxxxxxxxxxxxxx#aol.com'; // SMTP username
$mail->Password = 'yyyyyyyyyyyyyyyyyyyyyy'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('xxxxxxxxxxxxxxxxxxx#aol.com', 'Barry AOL');
$mail->addAddress('xxxxxxxxxxxxxxxxxxx#gmail.com', 'Barry gmail'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject - sent from AOL.com ';
$mail->Body = 'This is the HTML message body <b>in bold!</b> - sent from AOL.com ';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients - sent from AOL.com ';
$mail->send();
echo 'Message has been sent from AOL.com ';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
I'm getting the following error messages from PHPMailer and aol.com;
2018-04-22 21:44:56 SERVER -> CLIENT: 521 5.2.1 : AOL will not accept delivery of this message.
2018-04-22 21:44:56 SMTP ERROR: DATA END command failed: 521 5.2.1 : AOL will not accept delivery of this message.
SMTP Error: data not accepted.
Message could not be sent. Mailer Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: : AOL will not accept delivery of this message. SMTP code: 521 Additional SMTP info: 5.2.12018-04-22 21:44:56 CLIENT -> SERVER: QUIT
2018-04-22 21:44:56 SERVER -> CLIENT:
2018-04-22 21:44:56 SMTP ERROR: QUIT command failed:
I'm assuming I must have gotten the server, port and SMTPSecure settings wrong but can't figure what they should be. By the way, with the proper changes to server, port and SMTPSecure the code works for outlook.com.
This is running on MS Windows 10 desktop with Apache/2.4.27 (Win64) and PHP Version 7.0.9.
This article has the official SMTP server to use (unhelpfully hidden under the "POP3 & IMAP" section), and you appear to be using the correct details.
It may be a spam-filtering filtering problem; try setting $mail->XMailer = ' '; (there's a space in those quotes) to suppress the identification of PHPMailer.
This error seems to be very subjective on AOL's side - there are a zillion search results if you search for that error message, and you can see others sharing their frustration here and here
Otherwise I'd recommend contacting AOL postmaster support.
Try taking the word 'AOL' out of the display-name portion of your From address. Since most clients only show the display-name when listing mail, AOL doesn't like names that look like they might be from official AOL addresses.
In the company I work for we use microsoft exchange server and ofcourse ms outlook to send and recieve email.
on andriod we use exchange application as following to access our mail.
I am trying to use the following code to send emails IN php:
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.dom-domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password123'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('username#dom-domain.com', 'Mailer');
$mail->addAddress('recname#yahoo.com', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('username#dom-domain.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject tls587';
$mail->Body = 'This is the HTML message body tls587 <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients tls587';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
but the page loads alot and I get this error:
2017-04-02 13:13:45 Connection: opening to mail.dom-domain.com:587, timeout=300, options=array ( ) 2017-04-02 13:14:48 Connection failed. Error #2: stream_socket_client(): unable to connect to mail.dom-domain.com:587 (Connection timed out) [/home/xxxxxxx/public_html/ml/PHPMailer/class.smtp.php line 294] 2017-04-02 13:14:48 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2017-04-02 13:14:48 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
Keep noted that on your Android device you are mostly using Microsoft Active Sync via port 443. You do NOT use a native SMTP connection here via port 587 (which would be used via IMAP/POP3). The same is true for a plain Outlook connection where MAPI or MAPI over HTTP/Outlook Anywhere is used. Both do not use a native SMTP connection here and might be the reason why it isn´t working. BUT on your GMail Account you are mostly using IMAP as this isn´t an Exchange Server which support Microsoft Active Sync.
It might therefore possible that your Exchange Administrator didn´t configured the SMTP Connector for external Authenticated connections for Outlook users as this isn´t needed in your case and therefore disabled for security reasons. As you didn´t specify if you are the Exchange Administrator and which version you are using its not easy to give you a how to here. So instead of that, you should follow these howtos here from Microsoft:
Controlling SMTP Relaying with Microsoft Exchange
Configure authenticated SMTP settings for POP3 and IMAP4 clients in Exchange 2016
If you aren´t an Microsoft Exchange Administrator you can try to send emails via the Microsoft Exchange Webservices (see here). However as said above, the Exchange Administrator might run a special configuration here to secure the environment.
I have an email account with zoho.com that is configured and running. On GoDaddy, I am hosting my site and have configured my mail such that any mail sent via the website is received at zoho mail. This setup worked fine till last week. Now I am getting errors and I have no idea what triggers them.
I get the following error on GoDaddy server when I try to send a mail to any account:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host.
AND the following error on localhost for the same script:
SMTP -> ERROR: Failed to connect to server: A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond. (10060)
I have tried the following to correct the errors (on both localhost and GoDaddy) by:
Changed port number to 25,465 and 587
Changed smtp server from smtp.zoho.com to relay-hosting.secureserver.net
Changed ssl to tls and vice versa
Removed the SMTPSecure Parameter altogether
Increased timeout variable to 1000
Verified that the mail accounts exist and are up and running
Verified that mail accounts have valid passwords and usernames.
A working demo can be found here.I have echoed the errors out as well as the message to be sent just for the purpose of this question.
Edit 1 I commented out "$mail->Host="smtp.zoho.com" and got the following error:
SMTP -> FROM SERVER: SMTP -> FROM SERVER: SMTP -> ERROR: EHLO not
accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not
accepted from server: SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error:
Could not authenticate.
Does this mean that GoDaddy is not authenticating the credentials?
Edit 2: My settings on zoho mail are:
Incoming server: poppro.zoho.com, Port: 995, SSL (POP)
Incoming server: imappro.zoho.com, Port: 993, SSL (IMAP) Outgoing
server: smtp.zoho.com, Port: 465, SSL (POP and IMAP)
Try Using Following Code:
<?php
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
#require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 3;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.zoho.com';
// use
// $mail->Host = gethostbyname('smtp.zoho.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
//$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "care#subillion.com";
//Password to use for SMTP authentication
$mail->Password = "care#subillion";
//Set who the message is to be sent from
$mail->setFrom('care#subillion.com', 'care#subillion.com');
//Set an alternative reply-to address
#$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->AddAddress($touser, $username);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($msg);
echo $msg;
//$mail->AddAttachment('img/logo-dark.png');
$mail->Send();
// echo "Message Sent OK</p>\n";
} catch (Exception $e) {
// echo $e->getMessage(); //Boring error messages from anything else!
}
?>
EDIT: if still not working then you must have proper configuration settings as below(as example):
Non-SSL Settings
(NOT Recommended)
Username: jon#domain.com
Password: Use the email account’s password.
Incoming Server: mail.domain.com
IMAP Port: 143
POP3 Port: 110
Outgoing Server: mail.domian.com
SMTP Port: 25
Authentication is required for IMAP, POP3, and SMTP.
Battling PHPMailer for sending emails, not if my server configuration this wrong or my settings either mail or if my code is wrong. Here is the code I use
$nombre = $_POST['name'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
require 'vendor/PHPmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$body .= "<b>Hola</b>";
try {
//$mail->Host = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->Username = "test#mydomain.com"; // GMAIL username
$mail->Password = "12345678"; // GMAIL password
$mail->AddAddress($email, 'abc');
$mail->SetFrom('nhernandez#fullmecanic.com', 'def');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Config php.ini
[mail function]
SMTP = localhost
smtp_port = 25
extension=php_openssl.dll
Also configure my gmail account for non-secure everything I found in forums and it does not work and I get this application:
2016-05-03 19:58:37 CLIENT -> SERVER: EHLO mydomain.com 2016-05-03 19:58:37 CLIENT -> SERVER: AUTH LOGIN 2016-05-03 19:58:37 CLIENT -> SERVER: bmhlcm5hbmRlekBmdWxsbWVjYW5pYy5jbA== 2016-05-03 19:58:37 CLIENT -> SERVER: ODEzODI5My4u 2016-05-03 19:58:38 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 j80sm38623ywg.48 - gsmtp 2016-05-03 19:58:38 SMTP Error: Could not authenticate. 2016-05-03 19:58:38 CLIENT -> SERVER: QUIT 2016-05-03 19:58:38 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message Sent OK
If you look carefully, I after sending an email, print "Message Sent OK" and this appears, but also appears authentication error
Have you read Gmail XOAUTH2 Using Google API Client. Does it pertain to you?
Have you tried ping smtp.gmail.com and make sure you get a response from the server hosting your script?
Can also try port 587 instead.
Kind of just spit balling here based off their troubleshooting guide because I cannot test your set up.
I configured my mail server as in the following guide:
https://www.digitalocean.com/community/tutorials/how-to-configure-a-mail-server-using-postfix-dovecot-mysql-and-spamassasin
Now I am trying to send mails via PHP using this library:
https://github.com/PHPMailer/PHPMailer
But the problem seems the SSL (cert). I am not sure if the script is not able to establish a connection or if the problem is the unverified SSL cert.
Do you guys have any idea?
Should I use startssl oder starttsl in the script?
SSLaccept error from x.com[x.x.x.x]: 0
Dec 8 17:45:23 x postfix/submission/smtpd[13479]: warning: TLS library problem: 13479:error:14094418:SSL routines:SSL3READBYTES:tlsv1 alert unknown ca:s3pkt.c:1258:SSL alert number 48:
My code so far:
function send_mail($from, $from_name, $to, $to_name, $subject, $content)
{
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.x.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#x.com'; // SMTP username
$mail->Password = 'so secret'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->From = $from;
$mail->FromName = $from_name;
$mail->addAddress($to, $to_name); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $content;
$mail->AltBody = 'Please use an html compatible Client to view this mail!';
if(!$mail->send()) {
return false;
} else {
return true;
}
}
I had the same error, and finally figured out that phpmailer wants to use a normal smtp connection and then STARTTLS or STARTSSL to initialize encryption. In other words: it wants to connect to a submission service instead of an smtps service. Submission is on port 587 (usually) and smtps is on port 465. In fact, the smtps protocol was deprecated a long time ago. There are still many ISPs out there using smtps, but apparently they shouldn't.
If your mail provider allows you to use submission (port 586) instead of 465, then change your port number in your config and it will work! If you happen to be the sysadmin on the smtp server, then simply start a submission service, listening on port 587. If your ISP only supports smtps, then probably you are stuck. It seems that phpmailer does not handle SMTPS connections that are encrypted from the beginning. It only support connections that can be switched to encrypted (using STARTTLS).
The difference between the two is also described here:
What is the difference between ports 465 and 587?
UPDATE: before you try sending out any email, please update to the very latest version of phpmailer. Download the latest from github ( https://github.com/PHPMailer/PHPMailer ). Do not try to use any other version! Sometimes a small change in the minor version will decide between a successfully sent email and an "smtp connection error".