Laravel ElasticEmail Config - php

I'm struggling with configuring Laravel email. This is my first Laravel project, I am WordPress Web Developer.
And this is the error code I'm getting.
Expected response code 250 but got code "", with message ""
What am I doing wrong?
This is .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.elasticemail.com
MAIL_PORT=2525
MAIL_USERNAME=email#managedcloudhostingemail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=TLS
This is mail.php in config folder
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.elasticemail.com'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#bummit.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
I've tried almost every possible combination of ports, ssl, tls and can't figure out why email doesn't work. Email should be sent to new user registration, and I get this error, while user gets saved to database.

I have actuallly got wrong credentials from support, and sonce we're using Cloudways and have subscribed to Elastic Email through them, I had to use API key as username and password. Then everything worked like a charm.

I think you would need some more code to achieve this with ElasticMail.
Take a look at this wrapper, it allows you to easily use your ElasticSearch account.

You might want to use API instead of SMTP, as it is a better way to do that in the long term.
We constantly work on adding new plugins to most popular tools so a ready made solution will show up. I can't give you an exact date just yet.

Related

Symfony\Component\Mailer\Exception\TransportException with message 'Expected response code "250" but got an empty response.'

I'm using Google Workspace SMTP relay service to send emails from my Laravel app. It has been working well for over more than a year now, but I'm not sure what exactly stopped it from working.
When I try to send an email I get the following error:
>>> Illuminate\Support\Facades\Mail::to('myemail#gmail.com')->send(new App\Mail\CourseEnrolmentEmail($user, App\Course::first()));
// The error
Symfony\Component\Mailer\Exception\TransportException with message 'Expected response code "250" but got an empty response.'
I suspect it is related to my upgrade from Laravel 8 to Laravel 9, but not sure how to fix it.
My mail.php
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
],
My mail config
MAIL_DRIVER=smtp
MAIL_HOST=smtp-relay.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=TLS
MAIL_FROM_NAME="My Name"
MAIL_FROM_ADDRESS=myaddress#workspace.com
I'm authenticating via IP, so the password and username fields are not required
My GSuite Gmail routing configuration
Note
In the above config, I have tried checking TLS and also changing Allowed senders to "Only Registered Apps users in my domains" but the problem still persists.
I have tried suggestions from
https://laracasts.com/discuss/channels/laravel/laravel-swift-mailer-exception-expected-response-code-250-but-got-an-empty-response-using-gmail-smtp-relay-database-queue-driver
Laravel 9 - Infomaniak : Expected response code "250" but got code "550", with message "550 5.7.1 Sender mismatch"
https://stackoverflow.com/a/43283422/11752623
https://www.cubebackup.com/blog/how-to-use-google-smtp-service-to-send-emails-for-free/ Method 3
All of them were not successful. I appreciated your help in solving this issue.
Found a solution,
I went to vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php under the assertResponseCode method. I echoed the response which showed the following:
421 4.7.0 Try again later, closing connection. (EHLO) r29-200a50c01d0000xxxxxxxxxxxx87edb.28 - gsmtp
More details about the error from google documentation
The issue was that Swift Mailer was using 127.0.0.1 as the domain for sending the mail which was unknown to Gmail.
So, the solution was to set my domain name in the config/mail.php file
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN', 'mydomain.com')//this line here
],
More info:
https://insights.rytass.com/gmail-smtp-relay-421-4-7-0-try-again-later-closing-connection-ehlo-cfcdac3cf9c7
https://serverfault.com/questions/929559/postfix-error-421-4-7-0-try-again-later-closing-connection-ehlo

Laravel Gmail Configuration Error [duplicate]

This question already has answers here:
How to to send mail using gmail in Laravel?
(17 answers)
Closed 3 years ago.
I have been having this issue with Laravel email with Gmail and I have checked and reviewed so many questions on Stack Overflow but none still works in my case. I am using Laravel 5.4 and Xampp.
At first I thought it was my Xampp that cannot allow sending the emails but also when I move to the live mode(hosted it on a shared hosting) still have same issues there as well
But whenever I set the configuration to use Mailtrap, it's working and I know mailtap is just a development mail server, but whenever I use the Gmail it give me error such as "Expected response code 220 but got code "", with message """
Also when I try it on live mode it still gives same error.
My configuration file has the following
.env
MAIL_DRIVER=smtp
MAIL_HOST=gmail-smtp-msa.l.google.com (also tried smtp.gmail.com)
MAIL_PORT=587
MAIL_USERNAME=email#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'gmail-smtp-msa.l.google.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => 'email#gmail.com',
'name' => 'Name Here',
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', 'email#gmail.com'),
'password' => env('MAIL_PASSWORD', 'password'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Hey here is the solution
MAIL_DRIVER='smtp
MAIL_HOST='smtp.gmail.com'
MAIL_PORT=587
MAIL_USERNAME='sample#gmail.com'
MAIL_FROM_ADDRESS='sample#gmail.com'
MAIL_FROM_NAME='Some Name'
MAIL_PASSWORD='XXXXX'
MAIL_ENCRYPTION='tls'
As well as the configuration on the Laravel side, you need to enable "Less secure apps" in your Gmail account.
On the Laravel side, this guide shows the settings you need. Use smtp.gmail.com for host, and either 465/ssl or 587/tls.

Using mailgun on laravel 5.2 - failed to authenticate my sandbox account

I'm using Laravel 5.2 that has mailgun integrated. Was trying to send out email via SMTP but couldn't succeed because of the error:
Failed to authenticate on SMTP server with username
"postmaster#sandboxe56d93c917b144e98a4f07d1dbf2683a.mailgun.org" using
3 possible authenticators
I'm developing the app on my localhost with virtual host set up (i.e. app.dev.local) so I have to use the sandbox account to do all the testing.
These are the laravel's config/mail.php:
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => 'postmaster#sandboxe56d93c917b144e98a4f07d1dbf2xxxx.mailgun.org',
'password' => 'mypassword'
service.php's configurations
'mailgun' => [
'domain' => 'sandboxe56d93c917b144e98a4f07d1dbf2xxxx.mailgun.org',
'secret' => 'key-63sztbx99h-qdhp7j3-gp6346jsxxxx',
],
Everything looks good as I copied directly from my mailgun dashboard for the sandbox account, but the app still can't send out email due to failed authentication.
Does anybody know what is happening here?
Try with port 2525 maybe? You can edit it in the config/mail.php file where 587 is currently or through setting it in your .env file:
MAIL_PORT=2525
small correction
Check MAIL_DRIVER, MAIL_HOST, MAIL_PORT values in .env file. If you have this parameters set in .env file, function env call will take the values from that localization.

Swift_TransportException in Laravel 5.2 mail sending

I am trying to send mail for my laravel app from a gmail account with Allow less secure apps: ON and 2-Step Verification OFF
.env part for mail:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=library#gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=ssl
config/mail.php:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'library#gmail.com', 'name' => 'Admin'],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('library#gmail.com'),
'password' => env('********'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => env('MAIL_PRETEND', false),
First I tried using 'encryption' => env('MAIL_ENCRYPTION','tls'). But got the following error message:
ERROR: exception 'Swift_TransportException' with message 'Expected
response code 250 but got code "530", with message "530-5.5.1
Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257
z3sm16020712par.17 - gsmtp"' in
/home/shafi/Projects/Lib/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
I visited https://support.google.com/mail/answer/14257 and found everything is at the recommended state.
After this I used 'encryption' => env('MAIL_ENCRYPTION','ssl') but this time the same ERROR.
What should I do to fix the error? What am I missing?
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.
Note: If this still didn't help then retry the process couple of more times and wait then try to send the email from your Laravel apps. This should resolve the issue.
Step 1: Revert your config/mail.php to original file. The config/mail.php should look like this
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'library#gmail.com', 'name' => 'Admin'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
Step 2: The .env file should be like
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=library#gmail.com
MAIL_PASSWORD=whateverisyourpassword
MAIL_ENCRYPTION=ssl
Port is 465 and not 587
Step 3: Test the below code by pasting in appropriate controller function
\Mail::raw('This is an test e-mail', function ($message) {
$message->to("someone#gmail.com", "someone");
$message->subject("hi checking");
$message->getSwiftMessage();
});
P.S: Never ever forget to stop and then again start the server by using php artisan serve every time if some change is made to .env file. If not then you may be sucked into The Labyrinth of Time.
For me, sending mail worked by just adding the correct info in the .env file like so:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_gmail_email
MAIL_PASSWORD=your_gmail_password
MAIL_ENCRYPTION=tls
Don't change anything in the mail.php file. You don't want your email credentials all over the place. The .env file was made to store all of this.
I also turned on access to "less secure apps" on that Gmail account.
And lastly, run: php artisan config:cache
Hopefully that helps.
I had the same problem previously, the root cause was I changed the mail.php file.
To send email with smtp.gmail.com, you just need to change the configuration in .env file and enable allow less secure apps. Don't change anything in the mail.php file.
I'd recommend you to take the time to read this :
https://phpnotebook.com/how-to-fix-swift_transportexception-530-in-laravel-5-7.html

Connection could not be established with host smtp.gmail.com Laravel

I am trying to send a mail to my email-id. I have followed all the steps that might required to send a mail.
But it keeps on coming 2 errors
Connection could not be established with host smtp.gmail.com [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]
Maximum execution time of 30 seconds exceeded.
my controller is
public function contact()
{
Mail::send('clientinfo.contact',['name' => 'shweta'],function($message){
$message->to('myemail#gmail.com','Some Name')->subject('Welcome!')->from('otheremail#example.com');
});
mail.php file :
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'someone#example.com', 'name' => 'Some One Sender'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
Please help me through this.
Make sure you install Guzzle to your project by adding the following line to your composer.json file:
"guzzlehttp/guzzle": "~5.3|~6.0"
and editing your .env file with real email-id and password. Also, enable, less secure apps for that email-id as told by #Bharat Geleda
then your above code will run properly.
This is what I did.
I enabled two step verification on may gmail account
created separate apps password for my app here (screenshot below) (https://security.google.com/settings/security/apppasswords)
I that password into my laravel .env file and it worked.
screenshot
just select "Other(custom name)" on the "select app" and it will generate a password for you.
Use the MAIL_PORT=587 instead of the default mail_port in your .env file.

Categories