Send email with Google account using CodeIgniter - php

I'm trying to send emails with CodeIgniter using smtp.googlemail.com. No problems with code but Google is preventing me from sending that email - here's the email I received on my Google account:
A third party recently tried to use an application to connect to your
Google account.
We blocked the connection attempt in case it would be a hacker trying
to access your account.
If you have not made ​​this connection attempt, it may mean a third
party is trying to access your account. We recommend that you log into
your account and reset your password immediately. We blocked the
connection attempt in case it would be a hacker trying to access your
account.
If this is your account and if you are having trouble to get there,
follow the troubleshooting procedure explained at
http://support.google.com/mail?p=client_login.
I have followed the link and didn't find a solution.

I have the same issue, got an email from Google saying "Sign-in attempt prevented" when I was trying the same. I am ignoring what you have received from google and the text of email. Finally I solved the issue to send mail using CodeIgniter Email library today.
To use Google SMTP in CodeIgniter you need to make 2 (two) changes into Gmail account setting: (N.B. Please be aware that it is now easier for an attacker to break into your account -says Google)
Set off 2-step Verification.
Allow less secure apps: ON (or Enable)
Now use 'smtp_host' as ssl://smtp.gmail.com instead of smtp.googlemail.com
Hope this help.

Related

Failed to send email using codeigniter and phpmailer [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm having problems with gmail smtp server. I already read many posts here in StackOverflow about that subject.
The best post I found about test the connection is this one.
Although it is very well explained the error I'm getting I couldn't find a answer:
Google SMTP just says "Please log in via your web browser and then try again". I'm completely sure that the password and the email (both in base64) are well encoded.
As you can see here, in this image:
,
there is just one difference I can notice: the user#gmail.com and password is sent in two steps. In the link above the guy sends both at the same time. Google didn't accepted that.
But the fact is, I write
auth login Y29udGF0...
(user in base64, googles responds: )
334 UGFzc3dvcmQ6
(wich means "Password: ")
YzQ2MjJmNWVi.... (paste my password in base64 and hit "enter")
Then Goggle says:
Please log in via your web browser and then try again.
534-5.7.14 Learn more at https://support.google.com/mail/answer/7126229
And I'm going through all this problem because #MediaTemple and #DreamHost are not working with PHPMailer. I already use PHPMailer for a long time ago, in so many different hosts, using SMTP but failed with (mt) and Dreamhost. Now I'm in middle of a project that it >must< work on these two hosts.
I know this is an older issue, but I recently had the same problem and was having issues resolving it, despite attempting the DisplayUnlockCaptcha fix. This is how I got it alive.
Head over to Account Security Settings (https://www.google.com/settings/security/lesssecureapps) and enable "Access for less secure apps", this allows you to use the google smtp for clients other than the official ones.
Update
Google has been so kind as to list all the potential problems and fixes for us. Although I recommend trying the less secure apps setting. Be sure you are applying these to the correct account.
If you've turned on 2-Step Verification for your account, you might need to enter an App password instead of your regular password.
Sign in to your account from the web version of Gmail at https://mail.google.com. Once you’re signed in, try signing in
to the mail app again.
Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the
letters in the distorted picture.
Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your
account.
Make sure your mail app isn't set to check for new email too often. If your mail app checks for new messages more than once every 10
minutes, the app’s access to your account could be blocked.
I did this every time the problem happens:
https://accounts.google.com/DisplayUnlockCaptcha
problem sorted in my case!
I recently got this message, too, after I switched the data center location of a web application sending through Google SMTP.
The URL that apparently Google means is: https://support.google.com/mail/answer/78754. At that link, one of the steps is to reset your password. Not coincidentally, I also received an email from google with a subject of "Suspicious sign in prevented" that instructed me to change my password.
After resetting my password, I was back to using Google SMTP as usual.
I know this question is already been answered but for new comers those two solutions may help:
Make sure your gmail is allowing low secure apps to sign in, you can
turn it on here:
https://www.google.com/settings/security/lesssecureapps.
Change your password.
There are two ways to resolve this, and only one may work, depending on how you're accessing Google.
The first method is to authorize access for your IP or client machine using the https://accounts.google.com/DisplayUnlockCaptcha link. That can resolve authentication issues on client devices, like mobile or desktop apps. I would test this first, because it results in a lower overall decrease in account security.
If the above link doesn't work, it's because the session is being initiated by an app or device that is not associated with your particular location. Examples include:
An app that uses a remote server to retrieve data, like a web site or, in my case, other Google servers
A company mail server fetching mail on your behalf
In all such cases you have to use the https://www.google.com/settings/security/lesssecureapps link referenced above.
TLDR; check the captcha link first, and if it doesn't work, try the other one and enable less secure apps.
To send mail using Gmail SMTP, need to change your account setting. Login into your gmail accout then follow the link below to change your gmail account setting to send mail using your apps and program. https://www.google.com/settings/security/lesssecureapps
Note: This setting is not available for accounts with 2-Step Verification enabled. Such accounts require an application-specific password for less secure apps access.
I also came across this problem. Google detected my Mac as a new device and blocked it. To unblock, in a web browser log in to your Google account and go to "Account Settings".
Scroll down and you'll find "Recent activities". Click just below that on "Devices".
Your device will be listed. Okay your device. SMTP started working for me after I did this and lowered the protection as mentioned above.
There are at least these two issues I have observed for this problem:
1) It could be either because your sender username or password might not be correct
2) Or it could be as answered by Avinash above, the security condition on the account. Once you try SendMail using SMTP, you normally get a notification in to your account that it may be an unauthorized attempt to access your account, if not user can follow the link to turn the settings to lessSecureApp. Once this is done and smtp SendMail is tried again, it works.
Some apps are marked as less secure by google, so you just need to give access for those app so google will allow you to access its services to you.
follow this http://www.codematrics.com/your-imap-server-wants-to-alert-you-to-the-following-please-login-via-your-web-browser-gmail/

Using PHPMailer and gmail to send emails on Heroku

I want to log in to my gmail account from an Heroku app using PHPMailer but gmail restricts access since the remote server is an unknown device. Is there a workaround to this? I have tried using the captcha but its not helping.
Please note that i have no issue connecting to gmail on localhost. Problem comes when i deploy and my guess is that it is because gmail restricts it.
I actually stumbled across an answer. The solution is to actually follow this link and follow the instructions. First you have to allow less secure apps setting in your gmail account. Before following the link you have to sign out from all logged in accounts so that you do not allow for the wrong email. My mistake was that i followed the link before logging out thus allowed for a different email.

PHPMailer Hide SMTP Authentication?

Ok, I'm using PHPMailer to send email.
So in the php code I add my SMTP username, which is my gmail account
and the SMTP password, which is my gmail account password.
So my GMAIL ACCOUNT ACCESS is EXPOSED in php CODE, although the server
discards the php after it's been interpreted so nobody can see it, my question
is, is this reliable?
Should I leave my gmail access in the code or should I save it in my database?
Thanks in advance
Any developer with access to your code will be able to access your credentials. Saving these in a database may make it a little tougher to gain access to the details, but only slightly.
If you are truly concerned about the credentials used, create an account dedicated to your site and do not use a personal account.

PHP PEAR mail fails using Google Apps mail account - error 535 authentication failed

I have a PHP page that uses PEAR Mail to send a message through a Google Apps mail account. The page is only active in the fall and winter, and it was working great when it was last used in January.
Now, as I prep the site for the fall, this page no longer works. I have the exact same problem as described at SMTP Error 535 (Incorrect authentication data) using PEAR mail There have been no answers to that question and it won't allow me to comment, so I'm starting a new question.
I am using code identical to that posted by pavan kumar at Send email using the GMail SMTP server from a PHP page .
The error message is:
authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]
I double-checked that the login for the mail user had not been changed since January. I copied and pasted the address and password from my script into the Gmail login in my browser. It worked, so I know my parameters are correct. This account is a business domain address, not #gmail.com.
I am trying to connect at:
$host = "ssl://smtp.gmail.com";
$port = "465";
I also tried specifying tls:// and port 587, no luck. I also set the host to "googlemail.com" instead of "gmail.com" per a suggestion in another SO thread.
I did a var_dump() of the $smtp object, and confirmed my address and password were passed into it successfully and accurately.
The account is on a cPanel system that recently upgraded to PHP 5.3.5 and Apache 2.2.22. It seems unlikely that change could have triggered this problem, but I mention it in case it could be a factor.
Edit: Found http://support.google.com/a/bin/answer.py?hl=en&answer=176600 which says "...you must configure an SPF record for your domain with the IP address of the device or application to ensure that recipients do not reject mail sent from it. You must also add this IP address to the Email Whitelist box in your Google Apps control panel. For example. if your sending device sends from 123.45.67.89, add that address to your SPF record without removing the Google Apps mail servers from the record..." Unfortunately I don't have an Email Whitelist box in this domain - it's the free <10 user account which evidently doesn't have that feature.
Edit 2:
Related: http://support.google.com/mail/bin/answer.py?hl=en&answer=78775
Edit 3:
I set up the account in Opera mail, and sent successfully using both AUTH LOGIN and AUTH PLAIN settings.
The problem was located at my web host, not Google's mail server.
The account is on a cPanel server, and the admin had set it so that only designated user accounts could access external SMTP servers. He disabled that requirement in order for me to test, and my mail system immediately started working.
So far, though, I have found no documentation on how to log into cPanel as one of the authorized users when its SMTP Authentication is activated. I will update this if I find some.

using third party smtp

I run a website that allows users to send email newsletters using their SMTP, not the host's SMTP. In that case the user can connect directly with his/smtp to send email. I am aware that some hosting companies do not allow this. Does anyone know the way around this? I need to move my website from the present host.
You can use SwiftMailer (http://swiftmailer.org/). The user would need to give you there login information, but then you can login to their email account and send the emails from their account. This will work all the time since the host can't tell if it's a standard mail client trying to send email. You can even send through a gmail account.
If that's not what you want, then you are probably referring to relaying, which you can just give up on. Open relay has been one of the biggest security holes on mail servers for over a decade. Nobody should have that issue anymore.

Categories