connecting gmail to a laravel application: send and receive emails from withing the app - laravel

I'm trying to connect gmail to a laravel application so I can send and receive emails from withing the app just like this image: https://ibb.co/1QkDTTh.
I just don't have any idea how to start, so if any of you have a general idea on how this could be done please tell me. thanks.

try this
add the following code in .env file and then go to gmail security(https://myaccount.google.com/security) and then turn on less secure apps
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=your gmail Id
MAIL_PASSWORD=your gmail password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=info#example.com
MAIL_FROM_NAME=test

As far as I know you should allow less secure app to use your google account.
This can be done in your google account
Then you have to add your parameters to your config/mail.php file or in the .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_GMAIL_USERNAME
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl
now you can add your php code to send emails using your google account
use Illuminate\Support\Facades\Mail;
//...
$to_name = 'TO_NAME';
$to_email = 'TO_EMAIL_ADDRESS';
$data = array('name'=>"Sam Jose", "body" => "Test mail");
Mail::send('emails.mail', $data, function($message) use ($to_name, $to_email) {
$message->to($to_email, $to_name)
->from('FROM_EMAIL_ADDRESS','Artisans Web')
->subject('Artisans Web Testing Mail');
;
});
your view should be resources/views/emails/mail.blade.php
Hi <strong>{{ $name }}</strong>,
<p>{{ $body }}</p>
That's it

Related

Failed to send message from Laravel controller

I tried to send an email from a Laravel controller, but it's showing this error. I'm not using a two step verified Gmail account. Most tutorials use the "enable less secure app" settings, but I can't enable that option in my account.
this is my env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=******
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=********
MAIL_FROM_NAME="${APP_NAME}"
Please use your google app password in MAIL_PASSWORD

How to set up mailgun with laravel 5.7?

I am trying to set up mail sending with mailgun on my deployed laravel application. I am able to send email verification emails, but I can't send to my email. For example:
Notification::route('mail', 'admin#mywebsite.org')
->notify(new Feedback($user->email, $subject, $message));
When I was using mailtrap.io to test my mail sending it worked perfectly.
My .env file looks like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAILGUN_SECRET=key-<key>
MAIL_USERNAME=postmaster#sandbox<somenums>.mailgun.org
MAIL_PASSWORD=<mypass>
MAIL_ENCRYPTION=tls
When I try to send the email it brings this error: Expected response code 250 but got code "554", with message "554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings. "
welcome to SO.
Please have a deeper look at the Laravel official documentation where you can find everything you need to set up the mailgun driver.
Mailgun Driver
To use the Mailgun driver, first install Guzzle, then set the driver option in your config/mail.php configuration file to mailgun. Next, verify that your config/services.php configuration file contains the following options:
'mailgun' => [
'domain' => 'your-mailgun-domain',
'secret' => 'your-mailgun-key',
],
After updating your conf you have to change the MAIL_DRIVER env variable from smtp to mailgun. All the other settings for username, password and so on are not required.

How to send mail with laravel through gmail smtp?

I want to make contact Us page in my website, i have successfully do it with mailtrap, but when i want to send with gmail smtp server , i receive nothing and i get no error.
this is my .env mail config :
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=myemail
MAIL_PASSWORD=my_app_password
MAIL_ENCRYPTION=ssl
and code i use to send email:
$obj=new \stdClass();
$obj->contenu=$request->input('contenu');
$obj->objet=$request->input('objet');
$obj->email=$request->input('email');
$data=array('contenu'=>$obj->contenu,'email'=>$obj->email);
Mail::send("front.contactUs",$data,function ($message) use ($obj){
$message->from($obj->email);
$message->to('salondesbelleslettres#gmail.com')
->subject($obj->objet);
});
if(count(Mail::failures())>0){
return redirect()->back()->with('error','Votre demande na pas ete soumise');
}else{
return redirect()->back()->with('success','Merci de Nous Avoir Contacté');
}
Thanks.
Need to change your .env file to something like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache
You need to generate app password, and you can use that app password in .env file.
How to generate an App password:
Go to your Google Account
On the left navigation panel, click Security.
On the Signing in to Google panel, click App passwords.
(Note: If you can't get to the page, 2-Step Verification is:
Not set up for your account,
Set up for security keys only)
At the bottom, click Select app and choose the app you’re using.
Click Select device and choose the device you’re using.
Click Generate
Follow the instructions to enter the App password (the 16 character code in the yellow bar) on your device.
Click Done.
Once you are finished, you won’t see that App password code again.
Note: You may not be able to create an App password for less secure apps.
These settings worked for me instead.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
You should try this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremailaddress#gmail.com
MAIL_PASSWORD=gtxajikwsqmlaqcr // your app password
MAIL_ENCRYPTION=tls

forget password not working in laravel 5

I tried to click on link forget password and it says email has been sent but I didn't receive email
I am using gmail smpt in db config
I have already tried to change the setting in .env file but still nothing
This is mail config
MAIL_DRIVER=mail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=username#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
This isn't working it only says email has been sent but I didn't receive mail
I have also allowed in gmail to use Allow less secure apps: ON
so that app can directly send mail
You said you are using smpt driver. but in configuration you have set to mail.
So, you need to set MAIL_DRIVER from mail to smtp as given below:
'MAIL_DRIVER=smtp`.
Which password you are using ? Is that password which you are using to get login to gmail server ?
If yes then go to Myaccount of gmail then go to sign in and security and go to App password and generate password for Mail App and use that password.
May be that works for you. Same is working for me. Also change the following settings in your .env file.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=tls
I changed the value of MAIL_DRIVER from mail to sendmail in the .env file
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=email#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
In account setting of gmail allow unsecured app to send mail works for me

Laravel 5 google mail smtp issue

I am using laravel 5 for sending mail using google smtp. in my env file i set
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME={user}
MAIL_PASSWORD={pass}
and in my route
get('sendemail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.welcome', $data, function ($message) {
$message->from('alam.ifta#gmail.com', 'Learning Laravel');
$message->to('ifta123#gmail.com','Bappa')->subject('Learning Laravel test email');
});
return "Your email has been sent successfully";
});
it send email successfully, but in my inbox i see that the sender is not alam.ifta#gmail.com but from that account which i use in .env file. Where is the problem. Thank you.
Gmail does not let modify the address your emails come from. It's intended for personal use, not a server's outgoing mail.
If you want that, you need to use an email service designed for sending such emails. Laravel supports many of them out-of-the-box like Mailgun, Mandrill, and Amazon SES. Each has a generous free tier.

Resources