Email Not Being Sent in Laravel 8 using Mailgun Smtp - php

My email set up works well and send emails using my mailtrap set up but when I change the .env and mail.php file to that of Mailgun it does not sends the email. I only get a success message without any email. The emails I am using for testing are verified in my mailgun accounts
.ENV
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster#sandboxaf*********.mailgun.org
MAIL_PASSWORD=3b0d1862f55dcb18c62b***********
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=test#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
MAIL_SECRET=53774448859c1ffa6fad57b4a8*****************
MAIL_DOMAIN=sandboxaf49fa3222d1441e8*********.mailgun.org
MAIL_PASSWORD=3b0d1862f55dcb18c62bf***************
Mail.php
'default' => env('MAIL_MAILER', 'mailgun'),
'mailers' => [
'smtp' => [
'transport' => 'mailgun',
'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,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
]
Controller
Mail::to($request->email)->send(new PasswordResetMail($code,$url));
if (Mail::failures()) {
return response('failure');
}
else{
return response('success');
}
Have tried working on the suggestions from this
linkEmail Not Being Sent in Laravel 8 using Mailgun APIand this linkMailgun emails not sending from Laravel 8 Valet app as well as other links without any success

Related

Mail configuration settings changes in the .env file not taking effect in Laravel 8

I initially had my mail configuration settings in my .env file pointing to my gmail account and contact form was working fine. I have now changed my settings to point to a webmail and run php artisan config:cache but the mail is still being sent to my gmail. Below is my configuration settings and I've also tested the web mail by sending an email to it via gmail and sending back to gmail from the web mail and it's working fine. Any assistance is highly appreciated.
MAIL_MAILER=smtp
MAIL_HOST=mywebmail
MAIL_PORT=465
MAIL_USERNAME=sales#mydomain
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=sales#mydomain
MAIL_FROM_NAME="Laravel"
PS: My config/Mail.php
<?php
return [
'default' => env('MAIL_MAILER', 'smtp'),
'mailers' => [
'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,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
The problem was in my controller. I was sending email to my gmail instead of my webmail. I forgot to change that when I changed the mail settings. After changing mygmail to my webmail it works just fine.
public function store(Request $request)
{
$data = $request->validate([
//
]);
Mail::to('mygmail.com')
->send(new ContactMe($data));
return redirect(route('contact-us.index'))->with('flash', "Thank you,
we'll be in touch soon");
}

Why am I unable to send mail using laravel 8 gmail smtp? [duplicate]

This question already has answers here:
Laravel certificate verification errors when sending TLS email
(2 answers)
Closed 2 years ago.
I'm trying to send a mail from my localhost laravel 8 app using Gmail SMTP after entering the configurations but keep getting
Swift_TransportException
Connection could not be established with host smtp.gmail.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
I have turned on the Less Secure App settings on my gmail and even downloaded cacert.pem and added the location to my php.ini but it just keeps loading after submitting the form and then giving me the above error. What do I need to do to get it to work?
Here are my related .env file settings
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mygmailaddress
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=mygmailaddress
MAIL_FROM_NAME="${APP_NAME}"
mail.php
'default' => env('MAIL_MAILER', 'smtp'),
'mailers' => [
'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,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
php.ini
openssl.cafile=C:\wamp64\ssl\cacert.pem
openssl.capath=C:\wamp64\ssl
Maybe I'm supposed to change something in my mail.php file? Or just one of the fields in the php.ini should be present?
I've tried to change the smtp mail host, port and encryption to smtp.gmail.com, 465, and ssl in mail.php respectively, but that didn't work either. Neither did changing .env port to 587 and encryption TLS. What am I missing? Please help.
Fairly new to Laravel though, please be nice lol.
Can you try to change MAIL_PORT=587 . After than you need to give permission in your account to Less secure apps.

What's the correct configuration to send emails using Sendmail in Laravel?

I am using Laravel 7 and I want to send an email using the Sendemail driver via Laravel Mail facade. It worked when I used the PHP mail function but I want to use the Laravel Mail facade instead.
My .env file email configuration:
MAIL_DRIVER=sendmail
MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'
My default mail setup in config/mail.php:
'default' => env('MAIL_MAILER', 'sendmail'),
'mailers' => [
'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'),
],
'ses' => [
'transport' => 'ses',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
I have created Mail class as explained in the docs. What is the right configuration to make it work?
First, change the default MAIL_MAILER to use Sendmail.
MAIL_MAILER=sendmail
Then in config/mail.php, update the Sendmail line.
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs')
],
Finally, if you need to change the MAIL_SENDMAIL value then add this line to your .env.
MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'

vagrant laravel 5.3 gmail Expected response code 250 but got code "", with message ""

There are many post regarding this problem but none of them seems to fix my problem.
I'm trying to send email using gmail account from my local vagrant box.
My mail config:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => 'myaccount#gmail.com',
'name' => 'Example',
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
.env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myaccount#gmail.com
MAIL_PASSWORD=16digit_gmail_app_password
MAIL_ENCRYPTION=tls
My code:
\Mail::send('email.order',[], function($message) {
$message->to('other_email#email.com', 'John Smith')
$message->subject('Welcome!');
});
In my gmail account I acctivated 2-Step Verification and I created a app password (select app -> mail, select device -> Other/myLocalDomain.
When I try to send email I get Expected response code 250 but got code "", with message ""
I'm probably missing something here but I can't figure what.

Laravel 5.1 Mail::send how to know why it don't sends mails?

I am trying Laravel do a mail send. When I execute the code, nothing happens, no errors, no logs, no returning mails, anything.
Config Env
MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.es
MAIL_PORT=587
MAIL_USERNAME=noreply#domain.es
MAIL_PASSWORD=xxxxxx
MAIL_FROM=noreply#domain.es
MAIL_NAME=Domain Name
MAIL_ENCRYPTION=null
Mail.php
return [
'driver' => 'smtp',
'host' => env('MAIL_HOST', 'mail.domain.es'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'noreply#domain.es', 'name' => 'Domain Name'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', 'noreply#domain.es'),
'password' => env('MAIL_PASSWORD', 'xxxxx'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => env('MAIL_PRETEND', true),
];
Code in the controller
$accion = Accion::findOrFail($id);
Mail::send('emails.notificar', ['accion' => $accion], function ($m) use ($accion) {
$m->from(env('MAIL_FROM'), env('MAIL_NAME'));
$m->to("jtd#adagal.es", "Jtd")->subject('Nova acción formativa');
});
Did you see any error? I did everything that is marked in the official docs but still no response, no mail, no error.
pretend' => env('MAIL_PRETEND', true) change this to false
When the mailer is in pretend mode, messages will be written to your application's log files instead of being sent to the recipient.

Categories