I am using Laravel 8 + queues + Mailgun API to send emails from my local machine.
I can't send emails. I have this error :
[2020-12-19 11:50:26] local.ERROR: Connection could not be established with host smtp.mailgun.org :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:ssl3_get_record:wrong version number {"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.mailgun.org :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:ssl3_get_record:wrong version number at C:\\Users\\Dominique\\Documents\\Workspace\\market-gardener\\market-gardener-back\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\Transport\\StreamBuffer.php:269)
[stacktrace]
I think I have a configuration issues somewhere. I tried a lot of things without success. My conf :
.env :
MAIL_PORT=2525
MAILGUN_ENDPOINT=api.mailgun.net
MAILGUN_DOMAIN=sandbox___xxxxx_____________.mailgun.org
MAILGUN_SECRET=secret___xxxxxxxxxxxxxxxxx______
MAIL_ENCRYPTION=ssl
config/email :
'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',
],
Is this kind of conf correct? Where are my errors? Of course I already tried to clear the cache and config.
Here's a working version of the Mailgun setup I use:
MAIL_HOST=smtp.eu.mailgun.org
MAIL_PORT=587
MAIL_FROM_ADDRESS=address#example.com
MAIL_FROM_NAME=example
MAIL_USERNAME=address#example.com
MAIL_PASSWORD="123abc456def"
MAIL_ENCRYPTION=tls
The keys are coupled to the default config/mail.php file as seen here:
https://github.com/laravel/laravel/blob/8.x/config/mail.php
Note the usage of tls and port number 587. The MAIL_HOST may also differ. Mailgun should probably have a page on their website where this configuration is outlined.
A parameter was missing in the.env (see the doc here)
I only added MAIL_MAILER=mailgun in the .env , and it works fine now.
My .env is now :
MAIL_MAILER=mailgun
MAIL_PORT=2525
MAILGUN_ENDPOINT=api.mailgun.net
MAILGUN_DOMAIN=sandbox___xxxxx_____________.mailgun.org
MAILGUN_SECRET=secret___xxxxxxxxxxxxxxxxx______
MAIL_ENCRYPTION=ssl
You have to make sure you provide all the values of the environment variable
if not it won't work. in my own case, I added this line in my env file
MAILGUN_SECRET=6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxd
Related
Laravel version - 8
What Am I trying to do?
Sending email without env variable.
Error Details
Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.
Am i missing anything?
Code
config('MAIL_DRIVER', 'smtp');
config('MAIL_USERNAME', "email username");
config('MAIL_HOST', "smtp.gmail.com");
config('MAIL_PASSWORD', "password");
config('MAIL_PORT', "port");
config('MAIL_ENCRYPTION', "tls");
$invitedUser = new Admin();
$invitedUser->email = "recipient email address";
$invitedUser->notify(new TestingNotification());
config(['mail.mailers.smtp.host' => "host"]);
config(['mail.mailers.smtp.encryption' => "tls"]);
config(['mail.mailers.smtp.username' => "username"]);
config(['mail.mailers.smtp.password' => "password"]);
config(['mail.mailers.smtp.port' => "port"]);
config(['mail.mailers.smtp.from' => "from"]);
$invitedUser = new Admin();
$invitedUser->email = "recipient";
$invitedUser->notify(new TestingNotification());
It seems like there's something wrong with your configuration. The error mentions mailhog as a host, but that probably is not what you wanted.
Maybe you wrote things like config('MAIL_HOST', "smtp.gmail.com"); as pseudo code, but usually you'd set this up in your mail.php config file. For example:
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.gmail.com'),`.
...
]
]
I created realtime chat app using: Laravel 5.8, Laravel Echo, Redis, Socket.io and Vue.js.
It works fine on my local machine(localhost). But when I tried to move the app to production server(which has https) - it stopped working and it shows me the next error in laravel-echo-server.log file:
Also I've changed laravel-echo-server.json(echo server config file) like so:
Also you can see how window.Echo config looks like(in app.js):
import Echo from 'laravel-echo'
window.io = require('socket.io-client');
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
May be I have some bugs in the configs which mentioned above?
Also, I think it must be helpful, check the screenshot below what I have noticed in one of client's requests:
I tried to find more information about the error and why it could appear but no results. Exactly I checked laravel log file - it was empty, and nginx error.log file which was empty too, the only place where I saw error it's laravel-echo-server.log file(I shoved its content above)
for additional information you can check what settings I'm using for redis server in my .env file (I cleared cache when changed .env):
...
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
...
Also, that's what I have in my config/database.php file:
...
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'predis'),
],
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
],
...
Thank you guys so much for any help, I have been struggling with that problem for the last few days and I can't figure it out, so I will be gratefull for any tips!
Run This Command In Terminal
sudo nano /etc/hosts
Add your project host in Host entry
127.0.0.1 https://naturalselection.ie
And Save The File
After Run This Command In Terminal
laravel-echo-server start
And enjoy your live Notification With Laravel Echo
I sorted it out.
To fix that kind of issue you must go to /etc/hosts and paste there the next text:
127.0.0.1 your_domain_name.com
sudo nano /etc/hosts
127.0.0.1 your_domain_name.com
That's all, Hope it will help anybody :)
I am trying to use Mailgun
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
MAILGUN_DOMAIN=xxxxxxxxxx,
MAILGUN_SECRET=xxxxxxxxxx,
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The error is a strange one. Why would it be trying to connect to gmail?
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
Edit:
Now I am getting
"mail" => array:9 [▼
"driver" => "smtp"
"host" => "smtp.mailgun.org"
"port" => "2525"
"from" => array:2 [▶]
"encryption" => null
"username" => null
"password" => null
"sendmail" => "/usr/sbin/sendmail -bs"
"markdown" => array:2 [▼
"theme" => "default"
My MAIL_HOST was mailtrap.io, and it seems that that URL is not valid any more.
When I changed it to smtp.mailtrap.io it started working again.
It's look like your .ENV still have cache.
Please try this way
php artisan config:cache
php artisan cache:clear
And try to debug at your Controller
dd(env('MAIL_HOST'));
If it's still get smtp.gmail.com. Please try this way.
Edit your config/app.php. And add below 'env' => env('APP_ENV', 'production'),
'mail_host' => env('MAIL_HOST', 'smtp.mailgun.org'),
And try to debug at your Controller
dd(config('app.mail_host'));
I'm sure it's will show smtp.mailgun.org
After that you can delete the line you has just added to config/app.php
In your .envfile you should set
MAIL_HOST=smtp.mailgun.org
MAIL_USERNAME=(yourmailgunusername)
MAIL_PASSWORD=(yourmailgunpassword)
MAIL_PORT=587
MAIL_DRIVER=mailgun
You can refer to these tutorials for more informations
Mailgun setup with Laravel 5 example
Ultimate Guide on Sending Email in Laravel
After
php artisan config:cache
php artisan cache:clear
You probably also need to restart your web server.
This should be something really simple but all the tutorials are too old and I really don't know what half of these things are:
In config/mail.ph
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
So in my .env file I have:
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=(Default SMTP Login <- found in mailgun)
MAIL_PASSWORD=(Default Password <- found in mailgun)
I beleive these are all good. Next in config/services.php I have
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
And further in my .env file:
MAILGUN_DOMAIN=(API Base URL <- found in mailgun)
MAILGUN_SECRET=(API Key <- found in mailgun)
but when I run the artisan queue:listen I get error:
Client error: `POST https://api.mailgun.net/v3/-API Base URL-/messages.mime` resulted in a `404 NOT FOUND` response.
where -API Base URL- is the value of the MAILGUN_DOMAIN variable in my .env file
I tried putting my domain name mail.mydomain.com in the MAILGUN_DOMAIN but then I got the message to activate my account although the account was already verified and hence, I believe, active.
I tried leaving the MAILGUN_DOMAIN empty and then I got the
`POST https://api.mailgun.net/v3//messages.mime` resulted in a `404 NOT FOUND`
So, my conclusion is there should be something between ...v3/ and /messages.mime but I can't figure out what.
EDIT:
I found this:
https://laracasts.com/discuss/channels/laravel/laravel-and-mailgun-1
and it seems i can remove the MAIL_USERNAME and MAIL_PASSWORD but I don't know where to find this sandboxxxxxxxx code.
The right thing to enter is your domain name that you set up in mailgun. In my case it was mail.mydomain.com.
However, I never bothered to activate the account (you need to give them your phone number so that's most likely the reason I skipped it) so I was getting this message. Problem is solved now.
Hello i've been simply trying to send an email in laravel i read the documentation and they made it seem so easy but whenever i try i keep getting error after error, i tried sendgrid didn't work and now i'm trying to use mailgun but i'm having issues with it as well.
This is my code::
$data = array();
Mail::send('emails.auth.activate', $data, function($message)
{
$message->to('xxxxxxxxx#gmail.com', 'John Doe')->subject('This is a demo!');
});
This is the error i get:
GuzzleHttp \ Exception \ ClientException (400)
Client error response [url] https://api.mailgun.net/v2/mail.xxxxxxx.com/messages.mime [status code] 400 [reason phrase] BAD REQUEST
Mail Config:
<?php
return array(
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
|
*/
'driver' => 'mailgun',
'host' => 'sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org',
'port' => 587,
'from' => array('address' => 'mail#xxxxxx.com', 'name' => 'Xxxxxxxx'),
'encryption' => 'tls',
'username' => 'xxxxxxx#gmail.com',
'password' => 'xxxxxxxxxxx',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => true,
);
Follow these steps
First of all, install guzzle package by adding "guzzlehttp/guzzle": "~4.0" line inside composer.json
Update composer using composer update
Create your account on mailgun from http://www.mailgun.com/. After creating account, kindly note the mail gun subdomain created like sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org and API key created like key-65c33f1xxxxxxxxxxxxxxxxxxxx
Go to config/services.php file and replace
'mailgun' => array(
'domain' => '',
'secret' => '',
),
with
'mailgun' => array(
'domain' => 'sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org',
'secret' => 'key-65c33f1xxxxxxxxxxxxxxxxxxxx',
),
If you want to create your own sub-domain, you can create and assign to domain (as an alternative)
Configure config/mail.php like this
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => 'mail#xxxxxx.com', 'name' => 'Xxxxxxxx'),
'encryption' => 'tls',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false
Note that you do not need to supply username and password for this. Mailgun will handle this.
Try sending email now. Hope this helps. Good luck!
Just wanted to add one possible reason for the error. I received this error while using sandbox mode when I hadn't set the authorized recipient yet. When I logged into Mailgun and added the intended recipient to the "Authorized Recipient" list the error went away.
I had the same issue and kept getting the following error:
Client error response [url] https://api.mailgun.net/v3//messages.mime 404 not found
There isn't much written about this error written online for Laravel 5.1 which I'm using. It turns out that in the config->services the default Laravel 5.1 installation comes with :
'domain' => env('');
'secret' => env('');
for some reason if you keep your domain and secret wrapped in env as per default installation, the MailGunTransport doesnt pick it up. So just set it to the following:
domain' =>'yourdomain';
'secret' => 'yoursecret';
Hope this helps since I'm sure i'm not the only one who probably run into this issue.
I had this problem as I hadn't activated my mailgun account. Once activated all worked fine
I also stucked once in configuring the Mailgun in Laravel 5.1 and what worked for me is the following process. Hope its helps someone:
1) Install guzzle package by adding "guzzlehttp/guzzle": "5.0" line inside composer.json like this:
"require": {
"guzzlehttp/guzzle": "~5.0"
},
2) Update composer using sudo composer update in the terminal.
3) Restart Apache.
4) Create the account in http://www.mailgun.com. It will create a Sub Domain and API Key.
5) Add the Sub Domain and API Key in the .env like this:
MAILGUN_DOMAIN=sandbox8...........3b.mailgun.org
MAILGUN_SECRET=key-9..................04
6) And in the services.php add these line:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
7) Now the mail.php as follows:
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => ['address' => null, 'name' => null],
'encryption' => 'tls',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
I hope this works for you all.
You will be able to send mail to the persons in the same domain unless you have added them in the authorised recipient category.
If you add someone to authorised recipient category then he/she would have to approve the request and then only would be able to receive the emails.