I'm trying to use mailgun in laravel 9 but I always get this error:
Symfony\Component\Mailer\Exception\HttpTransportException: Unable to send an email: 404 page not found
My env:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=xxxxxxx
MAILGUN_SECRET=xxxxxxx
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_ENCRYPTION=tls
My mail.php
'default' => env('MAIL_MAILER', 'mailgun'),
My services.php
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
Try replacing "tls" with "starttls" for your MAIL_ENCRYPTION value
MAIL_ENCRYPTION=starttls
Related
I am trying to send email using gmail smtp in my laravel application which was working fine yesterday and emails were sending but today it is giving me this error. I tried every possible way but haven't figure out what is the problem. Any help would be appreciated. Thank you.
Here is my .env setting for smtp server
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=myemail
MAIL_FROM_NAME="${APP_NAME}"
I tried by changing
MAIL_PORT= 465
MAIL_ENCRYPTION = ssl
I also changed
MAIL_MAILER = sendmail
Still it is giving me the same error. I also allow access to unsecured apps from google but the error didn't go.
You can try to disable SSL Verification to check what's the problem. Open your config/mail.php file and add stream options like this:
<?php
return [
'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,
// region Disable SSL Verify
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
// endregion
],
],
];
Note: This method is the only testing method to determine the problem, not the final solution due to security reasons.
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.
I know this question has been asked many times before, but I have attempted a lots of these solutions without any success.
Hello i have issue in sending mail to laravel as its working fine but after migrating site to other server with ssl and now having issue as its giving below error.
Expected response code 220 but got code \"\", with message \"\"
below is the code used for .end and mail.php
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
mail.php
<?php
return [
'driver' => env('MAIL_DRIVER'),
'host' => env('MAIL_HOST'),
'port' => env('MAIL_PORT'),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'developer.eww#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'GBAN'),
],
'encryption' => env('MAIL_ENCRYPTION','tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/lib/sendmail -i -t',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
I have just moved my laravel 5.5 website to a server (digitalocean, debian9). For some reason emails wont get sent from my server and I'm not getting any errors.
.env:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAILGUN_DOMAIN=MYDOMAIN
MAILGUN_SECRET=key-SECRET_KEY
MAIL_USERNAME=MYUSERNAME
MAIL_PASSWORD=MYPASSWORD
MAIL_ENCRYPTION=tls
config/mail.php:
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'MY_EMAIL'),
'name' => env('MAIL_FROM_NAME', 'NAME'),
],
'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'),
],
],
];
config/services.php:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
send mail controller:
public function sendMail( $id, Request $request )
{
$user = User::find($id);
$data = [
'subject' => $request->subject,
'bodyMessage' => $request->message,
'image' => $request->image,
];
Mail::to($user->email)
->send(new test($data));
Session::flash('email', 'Message !');
return back();
}
I looked through my UFW firewall and i couldn't see anything related to mail getting blocked.
My email Service (mailgun) doesn't output anything in the logs when i try to send a mail. So I guess its not even reaching them.
I have no idea what to do at this point. I don't even know where I should look for the problem, is it a server problem? laravel problem? firewall problem?...
Would really appreciate some help!
Well, you can check several things :
• Is your production .env correct ?
• Have you make a composer-install recently ?
• Are you sure the php versions of your dev and prod environnement are the same ? because Swift Mailer requires PHP 7.0 or higher (proc_* functions must be available).
I have no idea why it didn't work, feels like i tried everything. Ended up using PHPMailer instead, which worked fine.
I am using laravel 5.2 with mailgun. Tried sending an email to a user in order that the user resets password. I get this error
ClientException in RequestException.php line 107:
Client error: POST https://api.mailgun.net/v3/sandbox7337ad8917084e1883b28134ba711960.mailgun.org/messages.mime resulted in a 400 BAD REQUEST response:
{
"message": "Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authoriz (truncated...)
This is a section of my .env file
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=postmaster#sandbox......mailgun.org
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAILGUN_DOMAIN=sandbox..........mailgun.org
MAILGUN_SECRET=key-.........
config/services.php file
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
config/mail.php file
'driver' => env('MAIL_DRIVER', 'smtp'),
host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 2525),
'from' => ['address' => 'myemail#gmail.com', 'name' => 'myName'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
Please, help.
This is the sandbox domain. You need to verify your own domain or verify the recipient in order to send an email to others.
Follow the link to add recipients: https://mailgun.com/app/testing/recipients