I am trying to send mail via the mailgun API from my controller but the mail is not reaching mailgun and I am not getting any error messages/logs.
This is in my .env:
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
This is in my services.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third-party services such
| as Mailgun, Postmark, AWS, and more. This file provides the de facto
| location for this type of information, allowing packages to have
| a conventional file to locate the various service credentials.
|
*/
'mailgun' => [
'domain' => env('subdomain.domain.ca'),
'secret' => env('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
];
This is in my mail.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/
'default' => env('MAIL_MAILER', 'mailgun'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| "postmark", "log", "array"
|
*/
'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',
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#domain.ca'),
'name' => env('MAIL_FROM_NAME', 'From name'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown-based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
This is how I am sending the mail in my controller:
Mail::send('emailtemplates.trackeremail', $data, function($message)use($data, $pdf) {
$message->to($data["toaddress"])
->cc($data["ccaddress"])
->subject($data["title"])
->attachData($pdf->output(), "PDFName.pdf");
});
This is working when I send to mailgun via SMTP in my local environment but I am unfortunately limited to shared hosting that does not allow 3rd party SMTP and I need to switch to the API method for production. I have gone through many tutorials and questions on this site (and others) related but nothing has solved my issue.
I always run php artisan config:clear after any kind of .env change.
Is there anything else that I can be doing to even get an error message or further debug this? Any help would be appreciated.
It might possibly be the port, host, encryption, and mail from:
Keep these as is in your .env:
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Enter these in your .env:
MAIL_FROM_NAME=YourNameHere
MAIL_FROM_ADDRESS=enter#theemail.com
MAIL_FROM=enter#theemail.com
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
Update services.php with:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
],
Update mail.php with adding:
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'port' => env('MAIL_PORT', 587),
After going over this with A2 Hosting's technical support it turns out that this is just not possible with their shared hosting, I was informed that "Mailgun only supports the standard SMTP ports, so it is not supported on our shared server".
Related
i have problem with register new user when i register new user this error shows up
"Swift_TransportException
Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known."
My .env file looks like :
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxx
MAIL_ENCRYPTION=null
my mail.php configuration looks like:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/
'default' => env('MAIL_MAILER', 'smtp'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| "postmark", "log", "array", "failover"
|
*/
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'mailhog'),
'port' => env('MAIL_PORT', 1025),
'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' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -t -i'),
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'log',
],
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
you have a missing variable you need to add the mail from:
MAIL_FROM_ADDRESS=myemail#domain.com
i need to add smtp to laravel 7 but when i try to send message he give me that error:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
i tried to add gmail and mailtrap and changing port and encypt and restart host but still not work
.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:K3vkVyYyoETJk/FWUQXkAmW44mRL0fcgiLw9fkFXsFk=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=edu
DB_USERNAME=jxo
DB_PASSWORD=jxo
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=465
MAIL_USERNAME=f6af4ce70a3cd0
MAIL_PASSWORD=578e9511c92977
MAIL_ENCRYPTION=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=me-south-1
AWS_BUCKET=
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}"
mail.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/
'default' => env('MAIL_MAILER', 'smtp'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| "postmark", "log", "array"
|
*/
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 465),
'encryption' => env('MAIL_ENCRYPTION', ''),
'username' => env('f6af4ce70a3cd0'),
'password' => env('578e9511c92977'),
'timeout' => null,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'mailgun' => [
'domain' => 'your-mailgun-domain',
'secret' => 'your-mailgun-key',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'test#test.com',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'test#test.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
OrderController
<?php
namespace App\Http\Controllers;
use App\Mail\OrderStarted;
use Illuminate\Http\Request;
use Mail;
//use App\Mail;
use App\Mail\OrderShipped;
class OrderController extends Controller
{
public function start(Request $request){
// echo $request->user();
// return;
Mail::to($request->user())->send(new OrderStarted());
// return view('email.start');
}
public function send(Request $request){
return view('email.send');
}
public function ship(Request $request){
return view('email.ship');
}
public function complete(Request $request){
return view('email.complete');
}
}
Im trying to implement laravel websockets and trying to access dashboard.
http://127.0.0.1:8000/laravel-websockets Address leads me to the dashboard on my local machine but when i host it and try www.mysite.com/laravel-websockets, it shows that the page doesn't exist.
Im using this package for laravel websockets and AWS EC2 Instance for hosting.
broadcasting.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "ably", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'null'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http'
],
],
'ably' => [
'driver' => 'ably',
'key' => env('ABLY_KEY'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
By default, access to the WebSocket dashboard is only allowed while your application environment is set to local.
However, you can change this behavior by overriding the Laravel Gate being used. A good place for this is the AuthServiceProvider that ships with Laravel.
public function boot()
{
$this->registerPolicies();
Gate::define('viewWebSocketsDashboard', function ($user = null) {
return in_array($user->email, [
//
]);
});
}
Refer to this doc https://beyondco.de/docs/laravel-websockets/debugging/dashboard#protecting-the-dashboard
I want to send email using smtp with my laravel 8 project. I have an example project in which this works. Using this configuration in my current project is unsuccessful.
I am unable to use the example 1 one 1 because the folderstructure is different. My example uses the default laravel folder structure, my current project has a modular layout in which each folder represents an entity that has its own controllers, models etc. I have been on it for a while and would appreciate outside advice in order to get it working.
The 'allow less secure apps' option is enabled in gmail.
The content of my test_mail.blade.php file is just some basic html.
Mail function is called from inside update function for convenience.
Frontend::email.test_mail , this points to a view that is in the same entity folder.
The example uses: /folder/subfolder/view, the rest of it is the same as the example.
$data = array("name"=>"testname", "employee_nr"=>"010" );
$subject = 'test_message';
$to_email = 'realtargetaddress#gmail.com';
Mail::send('Frontend::email.test_mail',$data, function($message) use( $to_email,$subject)
{
$message->to($to_email)->subject($subject);
$message->from($to_email,$subject);
});
configuration of .env file. (exact copy from example)
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465 # 587 for tls - 456 for ssl
MAIL_FROM_ADDRESS=some_address#gmail.com
MAIL_USERNAME=some_address#gmail.com
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=ssl # tls or ssl
MAIL_FROM_NAME="${APP_NAME}"
config/mail.php (also a exact copy from my example)
'driver' => env('MAIL_MAILER', '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'),
'sendmail' => '/usr/sbin/sendmail -bs',
'from' => [
'address' => env('MAIL_FROM_ADDRESS',
'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
Mail.php extends Facade
This class is in the Illuminate\Support\Facades namespace.
My example uses mail.manager in the getFacadeAccessor() method, which fails in my current project.
Using mailer instead of mail.manager does not produce errors but also does not work.
console commands that used after making changes to .env
php artisan config:clear
php artisan config:cache
php artisan cache:clear
edit The error that this gives me is:
Unable to resolve NULL driver for [Illuminate\Mail\TransportManager].
I searched with that but did not find a fix.
solution I was adviced to add the following code to mail.php, make sure to add it on top and to run the console commands. After i did this the mail function worked for me.
'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,
],
],
I have set the from address in config/mail.php. but in mail, from address is smtp username. Is that possible to change the from address without changing smtp credentials.
.env File
MAIL_DRIVER=smtp
MAIL_HOST=HOST_NAME
MAIL_PORT=PORT
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=PASSWORD
MAIL_FROM_ADDRESS=FROM_EMAIL_ADDRESS
MAIL_FROM_NAME=YOUR_NAME
config/mail.php
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
// 'from' => ['address' => null, 'name' => null],
'from' => [
'address' => env('MAIL_FROM_ADDRESS', null),
'name' => env('MAIL_FROM_NAME', null)
],
You should try this:
Just only change in config/mail.php in from array like
'from' => [
'address' => env('MAIL_FROM_ADDRESS', null),
'name' => env('MAIL_FROM_NAME', null)
],
After clear the cache and try:
php artisan cache:clear
php artisan config:cache
php artisan cache:clear