Laravel send email, configuration and send script - php

I have a problem with my laravel email client.
I need to send email by click button.
my code:
.env
MAIL_DRIVER=smtp
MAIL_HOST=mail.somedomain.com
MAIL_PORT=587
MAIL_USERNAME=test#somedomain.com
MAIL_PASSWORD=123456
MAIL_ENCRYPTION=null
I think it is good configuration, of course i'm using my domain :)
next in controller I have code like this:
Mail::send('home', array('firstname' => "fname"), function($message){
$message->to("testsend#somedomain.com")->subject('Welcome to the Laravel');
});
Website is open normally but email not send

In Gmail account
My account > Sign In And Security > Sign In to google, enable two step verification
http://i.prntscr.com/7c849cb520e84f02b39216f3662590bc.png
http://i.prntscr.com/cc52e9b8e7c2472496f1e2d2ec8185f8.png
Create One App and generate password
http://i.prntscr.com/b38cdca0724446d8a53b22dfa5f43ee6.png
In your .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword // this is created from gmail app password
MAIL_ENCRYPTION=tls
And Then run php artisan config:cache

Related

Laravel - unable to send email on production

I'm using ovh cloud server and laravel forge to manage my server, I don't know what happened exactly, I have websites and even wordpress installed , everything was fine and can send email from all websites, nowadays no website send email also no error in the log files, and the email function works fine but no email in inbox or even spam
I've tried changing mail to sendmail, the same issue
please advice me
MAIL_DRIVER=mail
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=noreply#****com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=noreply#*****.com
MAIL_FROM_NAME=“****”
If your using gmail, delete and create new app password. Here is my config
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=***#gmail.com
MAIL_PASSWORD="*****"
MAIL_ENCRYPTION=tls

Send Email through Proxy Laravel

I am trying to send an email to a guest in laravel.
Below is my code:
Mail::to($requestor->email)->send(new ApprovedNotification(auth()->user()->name));
The question is how can I send the email through proxy? Does it requires any server side configuration or I can just set it in laravel? The code is running fine when I am using my home network but when using my company server, the SMTP can't be sent out. ( The weird thing is the Jetstream team invitation email can be sent, but the customized emails cant)
Below is my email configuration:
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx#gmail.com
MAIL_PASSWORD=xxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=xxxxxx#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
Thanks in advance!
If you are using Gmail then you must generate App password.
https://support.google.com/accounts/answer/185833/sign-in-with-app-passwords?hl=en
then your mail configuration look like this
MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxxxxxx#gmail.com
MAIL_PASSWORD=xxxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=xxxxxxxxx#gmail.com
MAIL_FROM_NAME="${APP_NAME}"

Laravel email configuration for live server

I have installed laravel script on web server but unable to properly configure email settings. I want to use my hosting provider email on laravel script.
The script sends email when user register or request for verification code.
Find the .env file and edit the following with your smtp information:
MAIL_DRIVER=smtp
MAIL_HOST=host
MAIL_PORT=port
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null

Connection to tcp://smtp.mailtrap.io:587 Timed Out

I tried loading my page I created using laravel and after I hit the registration button and I got the above error message, please what must I do?
Mailtrap is an email testing service for testing. It will catch all the mail sent from your application, so you can test mails without sending it to client. In order to use it, you have to follow these steps:
First you have to create an account on Mailtrap. Then go to your dashboard and note your credentials. It may be something like:
Username: 05921688469af01
Password: 2efe39296ae5b7f
Then paste this values in your .env file of your Laravel application (the username must be pasted in MAIL_USERNAME and the password must be pasted in MAIL_PASSWORD).
It might look like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=05921688469af01
MAIL_PASSWORD=2efe39296ae5b7f
MAIL_ENCRYPTION=null
Then try again and it will work! You can go to your Mailtrap dashboard to see the result.
Check below settings if you are using in your .env file of root folder of project.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.yourdomainname.com
MAIL_PORT=2525
MAIL_USERNAME=email#yourdomainname.com
MAIL_PASSWORD= ********
MAIL_ENCRYPTION=null
Or
if you are using Gmail for sending a email then do following settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=******#gmail.com
MAIL_PASSWORD=*****
MAIL_ENCRYPTION=ssl
Try to use another SMTP port (2525, 465 or 25) https://mailtrap.io/faq#faq14
And also make sure to set your credentials which you got from mailtrap in .envfile
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your mailtrap username
MAIL_PASSWORD=your mailtrap password
MAIL_ENCRYPTION=null

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