Gmail SMTP issue - php

I have a problem sending an email using gmail's smtp server
Let me explain my situation. 1 week ago, i could send emails using php using smtp. Yesterday my host shifted their websites including mine to a different server. After that i am not able to send emails.
I tested the email scripts on my local machine and it worked just fine.
I am currently using phpmailer to send emails. When the error occurred, i enabled debugging on the php script. I ran the debugging enable version on the remote web server and my local machine.
Here is the output:
Local machine (works)
SMTP -> FROM SERVER:220 mx.google.com ESMTP dj6sm9229359qab.3
SMTP -> FROM SERVER: 250-mx.google.com at your service, [155.41.29.55] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK dj6sm9229359qab.3
SMTP -> FROM SERVER:250 2.1.5 OK dj6sm9229359qab.3
SMTP -> FROM SERVER:354 Go ahead dj6sm9229359qab.3
SMTP -> FROM SERVER:250 2.0.0 OK 1350437987 dj6sm9229359qab.3
Message sent!
remote server (doesnt work)
SMTP -> FROM SERVER:220-gds-wh1.get-sourced.net ESMTP Exim 4.80 #2 Tue, 16 Oct 2012 21:00:32 -0500 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-gds-wh1.get-sourced.net Hello gds-wh1.get-sourced.net [63.141.244.218] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> FROM SERVER:250 Reset OK
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
If you look closly. In my local machine it seems to have the google's mx-server address in the debug info, but in the remote machine it has the hosting providers info. I don't know if this is normal or not. I am totaly clueless
Could you help me or give me a clue as to what is wrong?
thanks,
Vidhu

Your hosting provider seems to be capturing outbound SMTP requests and forwarding them to their own SMTP server.
Are you connecting to Google on port 25? Instead, connect on port 587, the SMTP submission port. If you're already using 587, and your hosting provider is capturing THIS traffic, then send them a very nasty email threatening to switch hosting providers if they don't stop interfering with your web application immediately. This sort of BS may be tolerated by residential dial-up and DSL subscribers, but it's wholly inappropriate for web hosting and co-location.
If your provider is on the ball, they'll apologize and point you to the section in their terms and conditions that states that outbound SMTP traffic will now be automatically redirected until a removal request is placed via a support ticket.
Oh, and by the way, your new hosting provider has now captured the authentication credentials with which you authenticate with Google. Time to change passwords and implement TLS, though as far as I'm aware, TLS isn't supported by phpMailer.
Perhaps it's time to look at Swiftmailer or a commercial provider like Postmark ?

from what i see, i think you must check did you already put the correct SMTP of google (usually: smtp.gmail.com)?
and to using google smtp, it's required an authentication like user and password from your google account.

Related

SMTPError: Password command Failed PHPMailer

The Requirement is that when the form is submitted the mail has to be sent the specified email address. For this I am using PHPMailer.
When I ran the code first time from localhost, I received Critical Security Alert received in Gmail, which I resolved by turning on "Allow Less Secure Apps" and also
checked and approved the security event.Now the code works perfectly in localhost powered by xampp but not in shared hosting. When I hit the submit button in the Form page present in shared hosting, I get the following message:
2020-02-25 09:48:40 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP t131sm5033428oih.35 - gsmtp<br>
2020-02-25 09:48:40 CLIENT -> SERVER: EHLO www.domain_name.com<br>
2020-02-25 09:48:40 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [AAA.BB.CCC.DD]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2020-02-25 09:48:40 CLIENT -> SERVER: STARTTLS<br>
2020-02-25 09:48:40 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS<br>
2020-02-25 09:48:44 CLIENT -> SERVER: EHLO www.domain_name.com<br>
2020-02-25 09:48:44 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [AAA.BB.CCC.DD]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2020-02-25 09:48:44 CLIENT -> SERVER: AUTH LOGIN<br>
2020-02-25 09:48:44 SERVER -> CLIENT: 334 VXNlcm5hbWU6<br>
2020-02-25 09:48:44 CLIENT -> SERVER: [credentials hidden]<br>
2020-02-25 09:48:44 SERVER -> CLIENT: 334 UGFzc3dvcmQ6<br>
2020-02-25 09:48:44 CLIENT -> SERVER: [credentials hidden]<br>
2020-02-25 09:48:45 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 ymrjiXdYur3ddtR_6o2GrGNO2DfOQ7VhdphcGz7dq3__0gTNj1-oIXqZ__3KYGCWXt-ZC534-5.7.14 znNW-khosAGrPwCN1mDscVVYa5ms25Ann9jrAUU39WELRqwVrSmhOMGa91Ec4JRu>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 t131sm5033428oih.35 - gsmtp<br>
2020-02-25 09:48:45 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 ymrjiXdYur3ddtR_6o2GrGNO2DfOQ7VhdphcGz7dq3__0gTNj1-oIXqZ__3KYGCWXt-ZC534-5.7.14 znNW-khosAGrPwCN1mDscVVYa5ms25Ann9jrAUU39WELRqwVrSmhOMGa91Ec4JRu>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 t131sm5033428oih.35 - gsmtp<br>
SMTP Error: Could not authenticate.<br>
2020-02-25 09:48:45 CLIENT -> SERVER: QUIT<br>
2020-02-25 09:48:45 SERVER -> CLIENT: 221 2.0.0 closing connection t131sm5033428oih.35 - gsmtp<br>
SMTP Error: Could not authenticate.<br>
The PHPMailer code for sending mail follows:
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->isHTML();
$mail->Username = 'username#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('username#gmail.com');
$mail->addAddress('username#yahoo.com'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Mail subject';
$mail->Body = 'Mail Body';
$mail->send();
echo 'done';
} catch (Exception $e) {
echo "Mailer";
}
The following actions have been taken:
Username and Password combination is correct and is not expired.
Verified manually by logging via web and also sending mails from the
localhost.
$mail->SMTPAuth=false cannot be set because majority
of shared hosting providers seems to have disabled this for security
reasons (mainly to avoid spamming and sending of unsolicited emails)
Just for others info! To resolve this issue you have to go to:
https://myaccount.google.com/security?pli=1#connectedapps
then click Allow less secure app to YES
what does it mean to be less secure app? could we change our FAQ instructions and/or implementation so that users do not need to do this extra step?
if not possible, we should at least document in FAQ that user also need to change the setting on their google security account
Your solution :
Your server not supporting phpmailer.
Your account taken as a spam read here : Prevent mail to Gmail users from being blocked or sent to spam
Use or fix App password
If you've turned on 2-Step Verification and are trying to sign in to your Google Account through a device, mobile app, or desktop app, you'll need to enter an App Password.
See more and follow steps here : Use or fix App password
If you're using SMTP (i.e. you're calling isSMTP()), you can get a detailed transcript of the SMTP conversation using the SMTPDebug property. The settings are as follows:
Enabling debug output and troubleshooting
If you are having problems connecting or sending emails through your SMTP server, the SMTP class can provide more information about the processing/errors taking place.
Use the debug functionality of the class to see what's going on in your connections. To do that, set the debug level in your script.
Allow error levels For example:
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 4; //from 1 to 4 to get more details.
I had error almost same and this code was solved my problem because of my self signed certificate.
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
Once again see SMTP Debugging
Debug levels
Debug output format
Looks like you are trying to connect by curl api or something SERVER: EHLO if so! please add your codes to question.
Well, after a long battle I somehow managed to solve this. I activated DisplayUnlockCaptcha from the following URL:
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Probably because Gmail might have viewed the logins received from PHP file lying in hosting server as untrusted requests. This is because the hosting servers may reside in different places or countries and the login authentication request received would appear different other than the one from where the Gmail account is logged in frequently. So as a security measure, it would have use some captcha mechanism in the background (which which cannot be viewed)

Error sending email from local server

I am trying to test a simple contact form in codeigniter 3 from my local wamp server (os is windows 10) using my gmail account. I have done this many times before but now I get an error. I have read all Stack threads on the subject but they just tell me to do what I am already doing and it isn't working. I have contacted Google but they are also telling me to do what I am already doing.
I have set up my controller like this:
$config = array(
'protocol'=>'smtp',
'smtp_host'=>'ssl://smtp.gmail.com',
'smtp_port'=>465,
'smtp_user'=>'username#gmail.com',
'smtp_pass'=>'password',
'mailtype'=>'text',
'charset'=>'iso-8859-1',
'smtp_timeout'=>'30',
'crlf'=>'r\n',
'newline'=>'r\n',
'wordwrap'=>TRUE
);
$this->load->library('email',$config);
php.ini is configured correctly I believe. I have turned on 'Allow less secure apps' in my Gmail account and 2-step verification is off. But I still get this error:
220 smtp.gmail.com ESMTP b36sm5736977edd.67 - gsmtp
hello: 250-smtp.gmail.com at your service, [86.180.98.185]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials b36sm5736977edd.67 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Thu, 9 Nov 2017 10:22:00 +0000
From: "Mike Heath" <msheath#btinternet.com>
Return-Path: <msheath#btinternet.com>
To: mike24heath#gmail.com
Subject: =?ISO-8859-1?Q?=43=6F=6E=74=61=63=74=20=4D=65=73=73=61=67=65?=
Reply-To: <msheath#btinternet.com>
X-Sender: msheath#btinternet.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a042c4818341#btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
I am confident that my username/password are correct because I can use them to log in to gmail. What could possibly be going wrong? Grateful for any ideas.
I have just discovered the Test Mail Server Tool which is the complete answer to all my email test problems. Forget Sendmail, PHPMailer, Gmail etc
http://www.toolheap.com/test-mail-server-tool/

Amazon SES STARTTLS SMTP & ExpressionEngine

I am trying to send mail using Amazon SES SMTP with STARTTLS in ExpressionEngine . I am encountering the error below.
I'm unsure why it is complaining it can't send the AUTH LOGIN command before the STARTTLS command - STARTTLS has clearly already been sent. I have tried everything I can think of, and would appreciate it if someone could point me in the right direction.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-376766033
hello: 250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
Failed to send AUTH LOGIN command. Error: 530 Must issue a STARTTLS command first
from: 530 Authentication required
The following SMTP error was encountered: 530 Authentication required
to: 503 Error: need MAIL command
The following SMTP error was encountered: 503 Error: need MAIL command
data: 503 Error: need MAIL command
The following SMTP error was encountered: 503 Error: need MAIL command
500 Error: command not implemented
The following SMTP error was encountered: 500 Error: command not implemented
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Here's a proper fix.
It is two steps (you can safely ignore the explanations if you want) and does not involve editing any non-config Expression Engine files, so you don't break your upgrade path.
It has been tested it on two Expression Engine installs (each v2.5.3 - Build Date: 20120911) and it's working perfectly.
STEP 1 of 2: Manually edit your {INSTALLDIR}/expressionengine/config/config.php file and add the following three lines at the end:
/* These email configuration variables are required for Amazon SES */
$config['email_smtp_crypto'] = 'tls'; // TLS protocol
$config['email_newline'] = "\r\n"; // SES hangs with just \n
Explanation: The first line sets the default email cryptography to TLS (which SES requires). The second line changes the email newline character from the Expression Engine default of "\n" to the RFC 822 compliant "\r\n" (which SES also requires).
STEP 2 of 2: Via your EE Admin go to "Admin -> Email Configuration" and set the following:
Email Protocol: SMTP
SMTP Server Address: tls://YOUR-SES-SMTP-SERVER:YOUR-SES-SMTP-PORT (the incredibly important part being the tls:// in front of the address)
SMTP Username: your SES SMTP username
SMTP Password: your SES SMTP password
Explanation: Once you have an SES Verified Sender Email Address and You have been granted production access to Amazon SES (both of which need to be done through Amazon's SES Management Console), you can create an AWS account with SMTP credentials via the SES Management Console. In doing this, Amazon SES will give you your own credentials.
For example it should look like this (with wacky usernames and passwords):
EXAMPLE SMTP Server Address: tls://email-smtp.us-east-1.amazonaws.com:465
EXAMPLE SMTP Username: QSKHFTQMSQAKIAIJ6GFY
EXAMPLE SMTP Password: PeNqC2be3IAbNyhHddTbujwekIKoQE2dAhwr3FVzObjH
To test this via your EE Admin go to "Tools -> Communicate" and send an email.
Here's my fix. I haven't had time to figure our why it works but do share if you have the time.
In your EE config file add the following settings (two tls settings as there are multiple examples of either working???):
/* SMTP mail settings
-------------------------------------------------------------------*/
$config['mail_protocol'] = "smtp";
$config['email_smtp_crypto'] = "tls";
$config['smtp_crypto'] = "tls";
$config['smtp_server'] = "AWS-SMTP-ADDRESS";
$config['smtp_username'] = "AWS-SMTP-USERNAME";
$config['smtp_password'] = "AWS-SMTP-PASSWORD";
$config['smtp_port'] = "465";
$config['smtp_timeout'] = 30;
$config['email_crlf'] = "\r\n";
$config['email_newline'] = "\r\n";
Then modify the Codeigniter Email.php class along the lines of this post: http://ellislab.com/forums/viewthread/158882/
The only variation I made was to set $starttls = TRUE by default.
var $starttls = TRUE;

Sending mail from PHP - is the error at my end, or the Mail Server's?

I'm trying to send email via SMTP from my PHP script, running via CodeIgniter.
See below for the debug output. Is this indicative of a problem at my end with PHP (Unable to send email using PHP SMTP) or at their end (hello: 250-parrot.email-provider.co.uk - which would imply to me it has connected to their server, as the actual SMTP server I entered was mail2.email-provider.co.uk, so it seems to connect and redirect to this parrot thing).
My SMTP details I have confirmed to be correct, but it still says it fails to authenticate the password - even though this same password works in my native mail clients.
I've changed my site name and the provider's name (I didn't want to name-and-shame if it was my fault!):
220 parrot.email-provider.co.uk ESMTP Postfix
hello: 250-parrot.email-provider.co.uk
250-PIPELINING
250-SIZE 512000000
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN CRAM-MD5 DIGEST-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Failed to authenticate password. Error: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
from: 250 2.1.0 Ok
to: 554 5.7.1 : Relay access denied
The following SMTP error was encountered: 554 5.7.1 : Relay access denied
to: 554 5.7.1 : Relay access denied
The following SMTP error was encountered: 554 5.7.1 : Relay access denied
to: 554 5.7.1 : Relay access denied
The following SMTP error was encountered: 554 5.7.1 : Relay access denied
data: 554 5.5.1 Error: no valid recipients
The following SMTP error was encountered: 554 5.5.1 Error: no valid recipients
221 2.7.0 Error: I can break rules, too. Goodbye.
The following SMTP error was encountered: 221 2.7.0 Error: I can break rules, too. Goodbye.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Wed, 7 Dec 2011 13:30:16 +0000
From: "Mysite.com"
Return-Path:
To: myemail#email.com
Cc: myotheremail#email.com
Subject: =?utf-8?Q?The_Subject?=
Reply-To: "mail#mysite.com"
X-Sender: mail#mysite.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4edf6a68626d6#mysite.com>
Mime-Version: 1.0
Can be:
Wrong password.
Login method not allowed/recognized by server.
If you are using the codeigniter mail object, try:
$this->email->print_debugger()
Brute force method, go up one level from application and put in log_message/trace,etc, to debug the actual codeigniter code to see what is going on.
I had the same problem. I have set everything fine and got the same message.
The problem was in the fact that I have set to address with $this->email->to before I have applied smtp settings with $this->email->initialize($config). After I moved this line before all other settings, everything worked as it is supposed.

Sender address rejected

I'm trying to use PHPMAILER, but I keep getting:
SMTP -> FROM SERVER:220 smart6.bol.com.br ESMTP
SMTP -> FROM SERVER: 250-smart6.bol.com.br 250-PIPELINING 250-SIZE 13312000 250-VRFY 250-ETRN 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250 8BITMIME
SMTP -> FROM SERVER:250 Ok
SMTP -> FROM SERVER:553 : Sender address rejected: not owned by user X
SMTP -> ERROR: RCPT not accepted from server: 553 : Sender address rejected: not owned by user deltrem1984#bol.com.br
SMTP Error: The following recipients failed: deltrem1984#bol.com.br
What should I do?
Often for anti-spam purposes, "$mail->From" is required to be the same address as you use for login to your SMTP server.
If that is your case, you can use the "$mail->AddReplyTo" field for the senders address instead. Only a suggestion.
If it is not the solution, some extra debugging information can be enabled by setting
$mail->SMTPDebug = true;
You should also be careful about email address aliases, because your SMTP server may be rejecting your mails for that reason (it depends on server configuration).

Categories