Laravel 5: Sending Email - php

I am trying to send an email in laravel application.
Here is my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=ehsan.sani91#gmail.com
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=tls
And here is the Mail::send method:
Mail::send('email', ['name' => "EE"], function($m){
$m->to('ee#dx.com', 'Malik')->subject('Subjet of the email');
});
And here is the error:
Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp"
Any help?

Well, I got it. Infact the email was not authenticated because that email required a mobile phone authentication after login. changing to other email address that required just login credentials, it worked.
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail#host.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls

GMail SMTP requires encryption. Try changing setting as following.
MAIL_PORT=465
MAIL_ENCRYPTION=ssl

I made the following mistake:
I did not actually include the
'encryption' => env('MAIL_ENCRYPTION'),
to the array return in mail.php. I did include my host, port, username and password in the mail.php but not the encryption method (the encryption method I only included in the .env file), so trying out these mentioned solutions did bring a change in the error messages outcome, created a bigger confusion, but none solved the problem. Hope this helps someone!

Related

Error when I send email using Office365 in Laravel

In Laravel 7, I want to send email from my application using Office365, tried email password and app password none worked.
MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=my-email-here
MAIL_PASSWORD=my-email-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my-email-here
MAIL_FROM_NAME="App name"
In the above code MAIL_PASSWORD is my email password not app password
this configuration gives me the following error
Failed to authenticate on SMTP server with username "support#tingsapp.com" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "451", with message "451 4.7.0 Temporary server error. Please try again later. PRX4 [MRXP264CA0044.FRAP264.PROD.OUTLOOK.COM]
". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [MRXP264CA0044.FRAP264.PROD.OUTLOOK.COM]
In the second try I put App Password created in office.com as MAIL_PASSWORD value, but I get same error.
after changing the .env I run php artisan cache:clear and php artisan config:cache
Is there anything I missed, please
you need to put the password in double-quotes.
Replace: MAIL_PASSWORD=yourpassword
With: MAIL_PASSWORD="yourpassword"
after changing the .env just run:
php artisan cache:clear
You have to use your email instead of password on MAIL_FROM_ADDRESS like this
MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=my-email-here
MAIL_PASSWORD=my-email-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my-email-here
MAIL_FROM_NAME="App name"
or you can use smtp-mail.outlook.com as MAIL_HOST
MAIL_MAILER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
MAIL_USERNAME=my-email-here
MAIL_PASSWORD=my-email-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my-email-here
MAIL_FROM_NAME="App name"

How to fix error Swift_TransportException in Laravel 5.6

working with laravel 5.6 and I am going to send contact form details via the gmail. My .env file is look like this,
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myname#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
but when I send submit buttons following error is coming,
1/1) Swift_TransportException
Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. u21-v6sm32263983pfa.176 - gsmtp
"
in AbstractSmtpTransport.php line 383
how can fix this project?
I guess I have faced this issue when I had wrong password in .env for given email id

why google account id and password not working sometime and use 2nd step verification after gives a key in laravel 5.4?

Here are some required detail about configuration in .env file and this is working also.
Many times laravel frameworks is accepted only Google 2nd step verification after gives a keys instead of Google id password, so please anyone know why not working Google id password and 2nd step key working ?
My problem is Google Password or 2nd step verification key, Please help me.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=google ID
MAIL_PASSWORD=google ID Password
MAIL_ENCRYPTION=ssl
Please late me know if some needful information was missing.
Thank you in advance.
use like this one:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=25
MAIL_USERNAME=id
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
Firstly, you have to allow "unsecure" app access your Gmail. See: https://support.google.com/accounts/answer/6010255?hl=en
Then, if port 465 with ssl does not work for you, try with 587 and tls.
This always works for me:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_FROM_ADDRESS=<email_add>
MAIL_FROM_NAME="<name>"
MAIL_ENCRYPTION=tls
MAIL_USERNAME=<gmail>
MAIL_PASSWORD=<password>
p/s: use Google SMTP to dev ENV only

Laravel - Password Reset - CanĀ“t Send Messages

I used the artisan command "php artisan make:auth" And Users authentication and registration is working fine but for some reason the App just can't send the reset passwords email.
I was able to properly configure the env file and even receive the message; "We have e-mailed your password reset link!", but the email never reaches the recipient.
This is my env file:
MAIL_DRIVER=log
MAIL_HOST=smtp.liberumratings.com
MAIL_PORT=587
MAIL_USERNAME=website#liberumratings.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
I also tried the example below but a got this error:
(1/1) ErrorException
stream_socket_enable_crypto(): Peer certificate CN=*.locaweb.com.br'
did not match expected CN=smtp.liberumratings.com'
MAIL_DRIVER=smtp
MAIL_HOST=smtp.liberumratings.com
MAIL_PORT=587
MAIL_USERNAME=website#liberumratings.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
All my parameters are correct and I am able to send emails using the PHPMailer on the same server on another application.
The encryption might be wrong. Are you using SSL?
Remove the tls and try agian. Also your answer can be found here
Laravel SMTP driver with TLS encryption

Error while sending email on GoDaddy Server: Laravel 5.1

I am using inbuilt template of Login System in Laravel 5.1
When I use Forgot Password on localhost, everything works. Below are my keys in .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=userid
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
When I try the same thing on Godaddy server, I am facing the below error.
Swift_TransportException in StreamBuffer.php line 265: Connection
could not be established with host smtp.gmail.com [Connection refused
111]
Your env file must be like below
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=465
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=ssl
In your config/mail.php, the from value should be like below...
'from' => ['address' => 'pankaj#YourDomainName.com', 'name' => 'Sender Name'],
What's your domain Name in from ? or you can say, How to create Email account in GoDaddy ?
Login in your GoDaddy Account
Go to your Hosting Account.
Click Manage
Under Email category, Please click Accounts
Create an account if there is no email account.
and that's it.
So let's say you have email address like Pankaj#yourdomainname.com
Now, put this email address in config/mail.php for from field. That's it.
This will 100% fix the issue
I had a hell of a time trying to find an answer to this so hopefully this helps someone. I was able to relay using my GoDaddy email account settings for a while but for whatever reason that stopped working. I'm now using the standard PHP Mail function to send emails and here's the .env config for that. Not sure if port or encryption are necessary but it's working so left it as is.
MAIL_DRIVER=mail
MAIL_HOST=localhost
MAIL_PORT=465
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=ssl
Looking around web, it seems when using GoDaddy you need to use their relay SMTP with Gmail credentials when you want to send an e-mail.
So in your .env file instead of:
MAIL_HOST=smtp.gmail.com
you should use
MAIL_HOST=here_godaddy_relay_server
The exact value of relay server depends on hosting you have but it will be probably relay-hosting.secureserver.net so try first with:
MAIL_HOST=relay-hosting.secureserver.net
Further details: https://www.godaddy.com/help/what-is-the-name-of-my-hosting-accounts-relay-server-953+&cd=2&hl=en&ct=clnk&gl=us
For my shared hosting at goDaddy
I could configure my .env with the values from cPanel->Email Wizard->Configure Mail Client
For Config email to your Laravel project first, create an email account in the host and check config details.
Now config you .env file example:
MAIL_DRIVER=mail
MAIL_HOST=mail.22h.in
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
And your config/mail.php Should be like this.
'from' => ['address' => 'demo#domain.in', 'name' => 'Order Receipt'],
Clear your project cache and config , Run these command
php artisan config:Cache
php artisan cache:Clear
One of the reasons could be wrong Mail_RRIVER etc in the .env file. Please make sure you put the right information there, e. g. for GMAIL the following input will work!
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=**<YOUR_USER_NAME>**#gmail.com
MAIL_PASSWORD=**<YOUR_PASSWORD>**
MAIL_ENCRYPTION=ssl
Update for Laravel 7 and up
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null

Categories