I am trying to send emails with mailgun but they won't send and I have no idea why because i don't get any errors at all.
This is my code:
mail.php:
'driver' => env('MAIL_DRIVER', 'mailgun'),
services.php:
'mailgun' => [
'domain' => env('sandbox1e...60.mailgun.org'),
'secret' => env('key-146...419'),
],
EmailController.php:
public function send($email, $uuid = null)
{
if($uuid == null){
$uuid = User::get()->where('customer_email' , $email)->first()->email_confirmed;
}
return Mail::to($email)->send(new ConfirmEmail($uuid));
}
ConfirmEmail.php:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ConfirmEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $uuid;
public function __construct($uuid)
{
$this->uuid = $uuid;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('[email protected]')
->view('emails.confirm');
}
}
I have added the emailadress I want to send to in mailgun, but it's not working. Am I doing something wrong or is there any way I can debug this?
Your configuration is wrong:
'mailgun' => [
'domain' => env('sandbox1e...60.mailgun.org'),
'secret' => env('key-146...419'),
],
The env function looks for an environment variable with the name you provide and returns the value. You should change it to the name of an environment variable and define it in your .env or don't use the env function, but that's not recommended.
Whereas Esteban Garcia's answer is correct, I to wish improve it with code snippets showing how exactly the configuration should look like:
In your config/services.php
, leave the configuration as shown below:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
In your .env
file, that is where you define the actual mailgun credentials:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandbox1e...60.mailgun.org
MAILGUN_SECRET=key-146...419
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With