laravel 5.2 and mailgun - laravel-5

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.

Related

unsupported driver [https], laravel when deployed to heroku

I am trying to deploy a Laravel application to Heroku and connect it with a database which has already been deployed to Azure.
But I am having error "unsupported driver[https]".
My database.php:
<?php
use Illuminate\Support\Str;
return [
'default' => env('DB_CONNECTION', 'mysql'),
/
'mysql' => [
'driver' => 'mysql'
'url' => env('DATABASE_URL','https://firstsqlaap.scm.azurewebsites.net/phpMyAdmin/db_structure.php?server=1&db=localdb&token=51b0b3471e798a712e129bcd1ebe5b01'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '53082'),
'database' => env('DB_DATABASE', 'localdb'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'pass'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
];
My SESSION_DRIVER is set to database because when set to file it was saying 419 error. I do not have any migration files as my database is deployed to Azure.
How to resolve this issue?
This certainly isn't the right URL to use:
https://firstsqlaap.scm.azurewebsites.net/phpMyAdmin/db_structure.php
You appear to be pointing to an instance of phpMyAdmin. phpMyAdmin isn't a database server, it's a dataase client. It's a tool that you might use to interact with your database. You need to provide the URL to your actual database.
Your database URL should look more like this:
driver://username:password#host:port/database?options
For MySQL, driver:// is likely mysql://.
I don't have any MySQL databases running on Azure, but it looks like a real URL might be something like
mysql://user:password#your-database-instance.mysql.database.azure.com/your-database-name
Go into the Azure portal and navigate to your database instance. Then, in the left navigation panel, click on "Connection strings". The information you need should be there, though not in URL format. You can either build your own URL by plugging the right values in or use the individual settings in your config/database.php file.
I commented url and it work for me

How to set the laravel conf to use mailgun

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

Laravel Echo Server: "Error sending authentication request" on production using HTTPS (Private/Presence channel subscription_error)

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 :)

Database [] not configured Laravel 5

I create new db in phpmyadmin and new tables.
Then i do
public function next(Request $request){
$langs = DB::connection('mydb')->select('select * from lang');
}
and get
Database [compgen] not configured.
in my .env
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=123
in my config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '123'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'test_',
'strict' => false,
],
In my case I used 2 db connections and the second added was not cached, the command call:
php artisan config:cache
did the trick.
To see what's going on it was sufficient to output the $connections variable in DatabaseManager->configure method.
You're using single connection, so you don't need to specify it:
$langs = DB::table('lang')->get();
You should use connection() method only when you're working with multiple DB connections.
For me the connection worked in development but not in the production environment, so after a lot of searching, I had to rebuild the configuration cache and It has worked. I ran the following command in the laravel root directory:
php artisan config:cache
Anyone stumbling upon this - if you are using Laravel 5.4 or newer, you can setup a new database connection in config/database.php
'mysql_test' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_TEST', 'forge'),
'username' => env('DB_USERNAME_TEST', 'forge'),
'password' => env('DB_PASSWORD_TEST', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION',
],
'engine' => null,
],
I created 3 new env variables DB_USERNAME_TEST, DB_PASSWORD_TEST, DB_DATABASE_TEST
Edit .env with something like
DB_DATABASE_TEST=test_db
DB_USERNAME_TEST=local
DB_PASSWORD_TEST=localpassword
Make sure config is refreshed: php artisan config:cache
You should be able to run a database migrate on your new test database, like so:
php artisan migrate:refresh --database=mysql_test
In my case it was a bad database username. I had it set in my config/database.php as well as the .env file and one of them was different than the other. Found this thread when searching, thought this might help someone.
I struggled with this error for a few hours and found out solution that works for me. If you can not delete cache with php artisan config:cache because it throws error after you run it:
[InvalidArgumentException]
Database [] not configured
And if you are sure that your connections parameters are good then try manually delete bootstrap cache config files which are placed in app/bootstrap/cache folder.
Hope it helps someone.
make sure the parameters
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=dbuser
DB_PASSWORD="password"
and then issue,
php artisan optimize:clear
I had the same issue but when i added
'default' => env('DB_CONNECTION', 'mysql'),
to database.php.It seems to have solved the problem
if this error shows when you use the validation so it is simple :) just check all the validation rules and messages are written >
correctly
for me i faced this error and i solve it by replace only point by comma in the validation rules.

Sending Email with mailgun in laravel error

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.

Resources