PHPMailer works great, I've been using it for ages and it's pretty good. I have had version 5.2.9 on my server and have got the newer, 5.2.16 uploaded,
Now my sites have issues of:
"SMTP Error: SMTP connect() failed."
I have added $mail->SMTPDebug = 4; and it gives me this:
2016-11-15 17:18:10 Connection: opening to localhost:25, timeout=300, options=array (
)
2016-11-15 17:18:10 Connection: opened
...
removed excess repetative lines
...
2016-11-15 17:18:10 SERVER -> CLIENT: 250-mail.servernetwork.co.uk Hello www.domain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-11-15 17:18:10 CLIENT -> SERVER: STARTTLS
2016-11-15 17:18:10 SMTP -> get_lines(): $data is ""
2016-11-15 17:18:10 SMTP -> get_lines(): $str is "220 TLS go ahead
"
2016-11-15 17:18:10 SERVER -> CLIENT: 220 TLS go ahead
2016-11-15 17:18:10 SMTP Error: Could not connect to SMTP host.
2016-11-15 17:18:10 CLIENT -> SERVER: QUIT
2016-11-15 17:18:10 SMTP -> get_lines(): $data is ""
Nothing else has changed on the server. Reverting to PHPMailer Version 5.2.9 removes this error (and emails are sent ok).
I have also tried to update from 5.2.9 to 5.2.14 and 5.2.13 and the same error occurs. I have made no changes to the DNS and there are no DKIM or other identifiers set in the PHPmailer classes to allow version 5.2.9 but not 5.2.13 or 5.2.16 ones.
I'm using PHP Version 5.6.2.
Any clues as to why this is so?
The sending code:
(I realise the code is not the best but it's an older site I picked at random to test out PHPMailer 5.2.16)
$mail = new PHPMailer();
//$mail->SMTPDebug=4;
$mail->Host = "localhost";
$mail->WordWrap = 78;
$mail->isSMTP();
$mail->From = $fromMail;
$mail->FromName = "Website: ".$name;
$mail->AddAddress($toEmail);
$mail->Subject = $member['bizname'] . " Enquiry";
$mail->Body = $message;
if (!$mail->Send()) {
...
}
The proper way to initialize the settings is, note that you should set the $mail->SMTPAuth = true:
<?php
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com'; // Specify main SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
//Only if you have SSL/TLS on your server
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
...
After spending a day or so asking various related questions, I found the answer lies with an update applied in PHPMailer 5.2.10.
I found that while my server is TLS certified, there seems to be a problem with using a localhost Host; possibly that PHPMailer may be trying to check the certificate applies to localhost domain, which of course it doesn't.
I found a solution to sending mail via Localhost now is therefore to disable auto-TLS with the following:
$mail->SMTPAutoTLS = false;
Using this all emails now send correctly.
NOTE
As Bodi0 stated using SMTPAuth is best practise, however I didn't realise that it is unnessecary for localhost mail servers as the authenticaton is implicit.
Comments on this answer to a related question about ->SMTPSecure settings gives more details.
Related
I'm using PHPmailer to send account verification mail, I'm using AWS ec2 instance, however, that mailer is working fine in localhost but when I upload that to server emails are not going,
at first, i used SendGrid credentials to send emails, failed, then tried Gmail SMTP, failed, and somewhere I read that ec2 can't send emails, then I created SES also, still can't able to send.
searched on the web abt that but no answers are fixing my problem,
in localhost, in can send emails with the same code and with SendGrid of Gmail credentials, why I can't send with the server?
my PHP mailer code is:
$sub = "Thankyou For registration! Confirm Your mail to Login";
$mailBody = "<h1>You are successfully registered<br />Visit site to login</h1>";
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "tls://email-smtp.us-east-1.amazonaws.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = "smtp_username"; // SMTP username
$mail->Password = "smtp_password"; // SMTP password
// $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom("my_mail_id#gmail.com", "SMTP_REPLAY_NAME");
$mail->addReplyTo("my_mail_id#gmail.com", "SMTP_REPLAY_NAME");
$mail->addAddress("recipient_mail_id#gmail.com"); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $sub;
$mail->Body = $mailBody;
if(!$mail->send()) {
echo 'Message could not be sent.';
} else {
echo 'Message has been sent';
}
it shows Message has been sent but I cant receive emails, checked in spam folder also, no clue of mail!
even I have openSSL certificate also! opened SMTP port for both inbound and outbound in security group of ec2, everything working fine but PHPMailer!
Get your protocols straight. In the Host you're specifying tls, but telling it to connect to Port = 465, which will not work with TLS. Either change your Port to 587 (preferred) or change your encryption method to ssl. Enabling debug output (SMTPDebug = 2) will let you in on what's happening in the conversation with the server.
A perusal of the troubleshooting guide would probably help.
I am working on windows and I have enabled telnet client
In cmd prompt:
$telnet smtp.gmail.com 587
220 mx.google.com ESMTP dk3sm50678627pbc.32 - gsmtp
$Helo
250 mx.google.com at your service
$ mail from: <myuser#gmail.com>
530 5.7.0 Must issue a STARTTLS command first. dk3sm50678627pbc.32 - gsmtp
$ STARTTLS
220 2.0.0 Ready to start TLS
$ mail from:
C:\Users\{myuser}>
Connection to host lost.
Don't know What is the problem ?
Can anyone help me out , how i can send emails from gmail server using telnet from command line >
smtp.gmail.com requires TLS. The basic telnet client that comes with windows does not know how to negotiate TLS with a server. You may want to use openssl instead, which is able to negotiate TLS. See http://www.madboa.com/geek/openssl/#cs-smtp for an example of how to do this.
The gmail smtp must use smtp auth before you sending your email. The smtp auth need username and password.
see this link blow if you can read in Chinese.
http://linxucn.blog.51cto.com/1360306/837365
Last I sugguest you use java to ask gmail smtp server to send email, It will be more easy , becasue you needn't encode the smtp auth to BASE64 or anything else.
GOGOGO, good luck :)
Put into a VBS file, ie sendmail.vbs.
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "cat#gmail.com"
emailObj.To = "cat#gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "cat"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Ccat1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"
At Google's web site for GMail you have to turn this feature on for CDO to work.
At your Gmail page click Settings - Accounts and Import - Other Google Account Settings - [At very bottom of page] Allow less secure apps.
Also from memory you also have to click a link in an email the first time you use it (it's been a few years).
I am getting SMTP Authentication Failure on the server and the mail is getting send via the server SMTP only...
It appears to be a server configuration or related problem, but I am not sure.
This is the debug details:
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
Failed to authenticate password. Error: 535 Incorrect authentication data
from: 250 OK
to: 250 Accepted
data: 354 Enter message, ending with "." on a line by itself
250 OK id=1U8Pjp-0002As-FB
quit: 221 ************** closing connection
Your message has been successfully sent using the following protocol: smtp
While testing from my local system, this works and the email is being sent via sendgrid.me
Again, This may not be a SendGrid Problem, but if you have faced similar issue, Can you please tell me what is the problem here?
I am using CentOs and I have cPanel in the server. I believe we are using EXIM for mail server.
For anyone that comes across this in future and are using cpanel/whm, you need to 'disable' this option under 'SMTP Restrictions' in WHM.
I was able to resolve this.
The issue was my server was not allowing the use of external SMTP and using its own SMTP server. I changed the settings and now it works fine.
I am using centos 7 Finally it works!
I was getting this issue(tail -f /var/log/mailog):
to=<usmanali#example.com>, relay=smtp.sendgrid.net[169.45.113.201]:587, delay=0.3, delays=0.05/0.07/0.16/0.02, dsn=5.0.0, status=bounced (host smtp.sendgrid.net[169.45.113.201] said: 550 Unauthenticated senders not allowed (in reply to MAIL FROM command))
Then i changed file /etc/postfix/main.cf in this way that added following lines into end of file
mtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
mailbox_size_limit = 256000000
# Sendgrid Settings
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:apikey:SG.YOUR_SENDGRID_KEY
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
Then Installing postfix missing module dependency using:
sudo yum install cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain
Then restarting postfix
sudo systemctl restart postfix.service
For the past 2 hours I've been looking online to see if any other people encountered this problem, and it seems a lot has, bot none of the answers are working for me.
SMTP -> FROM SERVER:220 mx.google.com ESMTP vq7sm928004oeb.13
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.57.114.141] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.57.114.141] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 vq7sm928004oeb.13
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 vq7sm928004oeb.13
The following From address failed: my#email.com
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMPTAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 587;
$mail->Username = "my#email.com";
$mail->Password = "password";
I've tried almost every setting for PHPMailer, but can't figure out what's still going wrong, are there any server settings I need to take care of?
I also tried the normal php mail() function, but that's not sending mail either, although when using Drupal forms it just sends an email.
For first you must configure the correct server to send emails (see at gmail.com):
SMTP server address: smtp.gmail.com
SMTP user name: Your full Gmail address (e.g. example#gmail.com)
SMTP password: Your Gmail password
SMTP port: 465 or 587
SMTP TLS/SSL required: yes
In PHPMailer:
$mail->SMTPAuth = true; // There was a syntax error here (SMPTAuth)
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 465;
$mail->Username = "YOU#gmail.com";
$mail->Password = "YOUR_GMAIL_password";
My problem was that I use the 2-step verification. So I had to remember to go to Authorised Access for my Google Account & then assign a Application-specific passwords for the domain that I'm using to send the mail.
Just noticed I typed SMTP wrong in this line $mail->SMPTAuth = true;, correcting this solved my problem.
The suggested port+protocol-combination seems wrong to me, because it's different to the official phpMailer-wiki:
Don't mix up these modes; ssl on port 587 or tls on port 465 will not
work.
In PHPMailer:
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 587; //use port 465 when using SMPTSecure = 'ssl'
$mail->Username = "YOU#gmail.com";
$mail->Password = "YOUR_GMAIL_password";
Setting up mail in php can be quite hard. have you tried using port=25?
If you need more information, please let me know.
Emails work when I send a test one through: /admin/settings/smtp but not when it is triggered by an action: /admin/store/ca/2/edit/actions.
I get an error in watchdog "SMTP Error: Could not connect to SMTP host"
And the SMTP debug had some errors...
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 smtp.com ESMTP SMTPCOM (node-boca108.smtp.com)"
SMTP -> get_lines(): $data is "220 smtp.com ESMTP SMTPCOM (node-boca108.smtp.com)"
SMTP -> FROM SERVER:220 smtp.com ESMTP SMTPCOM (node-boca108.smtp.com)
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 -> FROM SERVER:
SMTP -> ERROR: RSET failed:
SMTP -> get_lines(): $data was ""
(There were more lines - approx 50 or so, but they did not appear to contain any errors)
Can anyone point me in the correct direction please?