John Davidson

php - Laravel 9 | Mailgun saying "Password is not set"

0 comments
Message:


I'm trying to setup an email system through my Laravel app via Mailgun, here's my .env file
(sensitive info is replaced of course)


APP_NAME=Laravel
APP_ENV=local
APP_KEY=***
APP_DEBUG=true
APP_URL=***

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=***
DB_USERNAME=***
DB_PASSWORD=***

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=memcached

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster@*****.mailgun.org
MAIL_PASSWORD=(provided default password for this domain)
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=*****@gmail.com
MAIL_FROM_NAME="${APP_NAME}"
MAIL_DRIVER=mailgun

MAILGUN_DOMAIN=*****.mailgun.org
MAILGUN_SECRET=(I'm not sure what to put here, I tried the API key provided when I signed up and also the Mailgun password)

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://meilisearch:7700

The error here is showing up pretty much no matter what I've tried changing. I can also supply the mail.php, controller, etc. if needed. I feel like it might be much simpler than that though.



My Answer:
To send emails using Mailgun in Laravel 9, you can follow these steps:

1. Install the Mailgun SDK by running the following command in your terminal:

composer require mailgun/mailgun-php


2. Update your `.env` file with your Mailgun API credentials:

MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=your-mailgun-username
MAIL_PASSWORD=your-mailgun-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=your-email@example.com
MAIL_FROM_NAME="${APP_NAME}"
MAILGUN_DOMAIN=your-mailgun-domain
MAILGUN_SECRET=your-mailgun-secret


3. Create a new Mailable class by running the following command:

php artisan make:mail TestMail


4. Update the `build` method in your Mailable class to define the email content:
php
public function build()
{
return $this->view('emails.test');
}


5. Create a new blade template for your email content in `resources/views/emails/test.blade.php`.

6. Use the `Mail` facade to send the email in your controller or wherever you want to trigger the email:
php
use Illuminate\Support\Facades\Mail;
use App\Mail\TestMail;

Mail::to('recipient@example.com')->send(new TestMail());


7. That's it! Your email should now be sent using Mailgun in Laravel 9.

Rate this post

4 of 5 based on 5903 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us