I'm trying to send an email using PHP Pear. It works when I send email using Gmail with this settings:
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'username#gmail.com',
'password' => 'password!2016'
));
But before I make this work, I have to "allow less secure apps" to access my account, which you can read here on how to do it.
I tried to use an Outlook account with this settings:
$smtp = Mail::factory('smtp', array(
'host' => 'tls://smtp.office365.com',
'port' => '587',
'auth' => true,
'username' => 'email#domain.org',
'password' => 'greatPasswordComesWithGreatResponsibilities'
));
but I get this error:
Failed to connect to ssl://smtp.office365.com:587 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.office365.com:587 (Unknown error) (code: -1, response: )]
I checked the official article by Microsoft regarding their SMTP settings. So I thought I have the right settings, but it's not working.
Am I missing something? Why do I get this error? Is there a setting I have to configure in my outlook account, like with the Gmail, before a third party app be allowed to send email?
This may not help but the title of your post just said Outlook account but the link and smtp settings refer to Office365 for Business accounts. I can't shed any light on the business account but if you actually have a personal Outlook.com account the settings are different. And, there is an option on the account you must change to enable pop/smtp access as you did with gmail.
The official Microsoft article is:
https://support.office.com/en-us/article/Add-your-Outlook-com-account-to-another-mail-app-73f3b178-0009-41ae-aab1-87b80fa94970?ui=en-US&rs=en-US&ad=US&fromAR=1
But, the summary is the smtp server is smtp-mail.outlook.com and to enable pop/smtp in your Outlook account look for Options > Managing your account > Connect devices and apps with POP.
Update:
If you are actually using business account, you should check this post which claims to have it working: https://stackoverflow.com/a/26004690/2891120
The key item in his code is he doesn't have "tls://" in front of the host name. I have a consumer outlook account and get a similar socket failure to you with tls:// prefix. If I remove that prefix I get much farther (set debug=true in factory) but fail later with an auth failure. Using 5.2.16 PHPMailer instead I successfully send mail but the headers leave me worried about spam rejection rates (no DKIM, SPF was softfail for my AWS entity, warning about -f, and others). And, the email did end up in the junk folder of my other test recipient #outlook.com. But I digress.
Related
I've already confirmed my custom domain and I'm always get this error:
554 Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings.
The following SMTP error was encountered: 554 Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Config:
$this->email->initialize(array(
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_timeout' => 30,
'smtp_host' => 'ssl://smtp.mailgun.org',
'smtp_port' => '465',
'smtp_user' => '***',
'smtp_pass' => '***'
));
What could be wrong? Try in both localhost / server - and the same error is shown. This is not credentials problem either cause I can see the logs on Mailgun dashboard.
Pretty sure that they changed their policy recently: "Without a credit card you are restricted to authorized recipients only."
You just need add CC to make it work. - They should put this message on the top of their registration page!!!
It's still free for first 10,000 though.
A bit annoying - but the solution is to add credit card to the account.
credit card need not be added. the error message clearly shows that no authorized recipients have been added. Mailgun allows 10,000 free emails for 30days, which can be used for testing (even from a local host) provided authorized email ids are added (upto 5). this can be done on the dashboard page. instructions given in the documentation. I have been testing out my mailer using a localhost (WAMP server) on 3 authorized email recipients that i've added. credit card is to be added only when the 10000 email quota is exceeded.
When I try to send an e-mail through my website running Laravel 4, I get this exception:
{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Here is my mail config:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'mymail#gmail.com', 'name' => 'myname'),
'encryption' => 'ssl',
'username' => 'mymail#gmail.com',
'password' => 'lol',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I've tried the disable link i've found by googling this issue except it didn't make a difference.
Is there a way to tell Google "stop blocking this IP, it's me" ?
I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.
They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.
Things will actually be more straight forward if you visit that link already logged in into your Gmail account.
Warning
As #kodfire stated:
On May 30, 2022, this setting will no longer be available.
support.google.com/accounts?p=less-secure-apps&hl=en
Go to this link and disable unlock Captcha
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Try this:
Change port to 587
Goto gmail setting https://www.google.com/settings/security/lesssecureapps
and active it.
https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.
So, This is how it worked for me (100%):
Activate 2 step Verification in google
Now you will be able to create app. Open it.
Create new app (other app) and give your app name.
Now generate password.
Next in laravel, Goto .env file and change
MAIL_USERNAME= 'App Name you created'
MAIL_PASSWORD= 'Generated Password for that app'
This should be able to send emails from your gmail account.
Please leave a comment if it doesn't works for you.
Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.
Remove the #gmail.com from username, already you mentioned smtp. So no need #gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.
When I try to send an e-mail through my website running Laravel 4, I get this exception:
{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Here is my mail config:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'mymail#gmail.com', 'name' => 'myname'),
'encryption' => 'ssl',
'username' => 'mymail#gmail.com',
'password' => 'lol',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I've tried the disable link i've found by googling this issue except it didn't make a difference.
Is there a way to tell Google "stop blocking this IP, it's me" ?
I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.
They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.
Things will actually be more straight forward if you visit that link already logged in into your Gmail account.
Warning
As #kodfire stated:
On May 30, 2022, this setting will no longer be available.
support.google.com/accounts?p=less-secure-apps&hl=en
Go to this link and disable unlock Captcha
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Try this:
Change port to 587
Goto gmail setting https://www.google.com/settings/security/lesssecureapps
and active it.
https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.
So, This is how it worked for me (100%):
Activate 2 step Verification in google
Now you will be able to create app. Open it.
Create new app (other app) and give your app name.
Now generate password.
Next in laravel, Goto .env file and change
MAIL_USERNAME= 'App Name you created'
MAIL_PASSWORD= 'Generated Password for that app'
This should be able to send emails from your gmail account.
Please leave a comment if it doesn't works for you.
Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.
Remove the #gmail.com from username, already you mentioned smtp. So no need #gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.
I know this question is asked many times and have different solutions and I have tried all but no one has worked. This is my settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=abc#mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
And application is currently running on Centos 7 OS.
I always get
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
I have tried all solutions, by Replacing: smtp.gmail.com with 173.194.65.108, or replacing smtp.gmail.com by gmail-smtp-msa.l.google.com. When I do these two steps, it got server not found error.
If I change mail driver from smtp to sendmail or mail, no error is thrown but no email is sent.
If I use ip address of smtp.gmail.com, I got same result. If I change port from 465 to 587 and encryption from ssl to tls, nothing happens.
I have also created a file in etc/gai.conf and put precedence ::ffff:0:0/96 100. It worked one time. But later after two hours, it stopped working and started throwing same error.
I have also tried using my gmail id but all in vain.
The only solution that I couldn't be able to test is verifying httpd_can_sendmail as whenever I run command getsebool httpd_can_sendmail I get getsebool: SELinux is disabled. Is this the problem or is there any other way to get it fixed?
Here is my working mail config file:
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => '*******#gmail.com', 'name' => '****'],
'encryption' => 'tls',
'username' => '*******#gmail.com',
'password' => '*******',
'sendmail' => '/usr/sbin/sendmail -bs',
];
but from your question i can see you already tried all this, so i can assume it is a network problem based on error 'connection time out', what i mean is that something is blocking your connection, it might be your firewall if you have.
so first you should check that the port 587 is open, or you can check if other application can connect with smtp.gmail.com (don't know how to do it in centOs).
And at last this might not be a problem but you have to enable 'Allow less secure apps' in your google account just for testing. (This is not permanent solution but for testing, if it works then you should enable two step verification in google account and then create new application, you can create new special password which you can use as your password for smtp server)
In my case it was necessary to clear config cache to pull up .env file new settings
php artisan config:cache
Since you are using gmail, but I don't know what password you are setting, the MAIL_PASSWORD variable must be the same as the gmail application password. In this case, Gmail provides a third-party application service so that these, (in this case your application), can send emails using this type of authentication.
I've a laravel app nad I've been testing it with gmail smtp server and It was working in my system's localhost but then I deployed it on server (blue host) and change the configuration and still the app thinks that is sending emails and it's not giving me errors but no email is delivered to corresponding email addresses....
Here's my mail.php in app folder:
return array(
'driver' => 'smtp',
'host' => 'mail.mash-up.fi',
'port' => 26,
'from' => array('address' => 'registration#mash-up.fi', 'name' => 'Admin'),
'encryption' => 'tls',
'username' => '************',
'password' => '******',
'sendmail' => '/usr/bin/sendmail -bs',
'pretend' => false,
);
where I'm doing wrong?
any help is appreciated
If you are using the BH DNS(ns1.bluehost...), then check to see that the $from address is an existing email in your BH account.
(go to your CP /domain manager and use whois info to find that out.)
or.....
maybe, you migrated the source code, but did you transfer your domain name to BH, or is it pointing to BH servers (DNS)
In that case your site is not using the BH mail servers.
example :your site content could be on BH, but if it is registered somewhere else and the DNS is not ns1.bluehost.com..etc, then your domain might be using url forwarding or framing (to bring visitors to the BH location). but your mail functions may be handled by the registrar's
hope this is not too confusing
it is also helpfull if you post your domain name here and others can help figure out as well.
Please try to check the spam folder of where your sending to. If there is nothing, make sure your "from" is truly your bluehost email account your using to send the email. If the actual sender doesn't match the "from" of the e-mail many mail clients will ignore it entirely (like hotmail), but gmail will put it in the spam folder with a warning.
The host should be your bluehost box I think. In fact on cpanel, go to email, where you create accounts. Then click on "More", select "Configure Email Client", scroll down. You will see the host name, and port.
TTL/SSL would likely need port 465, I am guessing (I use the latter, not the former like you).
Open up the laravel.logs file inside of storage > logs. It should help give you some idea of what the problem might be.