500 means that you have made something wrong in the code, and without the full error message we can't even begin to guess what the issue is.
Error 500 when sending emails
Hello,
I am faced with really perculiar problem. I moved a Laravel 7 website from cpanel to an nginx-based web panel on ubuntu. (Cloudpanel.io)
That caused a few incompatibilities but with some help and modifications (including translating .htaccess to vhost configuration) I was able to have it running.
Right now I have a part of the website functions not working. It's the emails.
Whenever users try to sign up they should receive an email that is generated with the following code:
Mail::send(['html' => 'emails.sxm_user_activation'], $emaildata , function ($message) use ($emaildata) {
$message->from(env('SXM_MAIL_NOREPLY'), env('SXM_SITE_NAME'));
$message->to($emaildata['email'], env('SXM_SITE_NAME'))->subject(env('SXM_SITE_NAME').': Account Activation');
});
That part of the code creates a white screen and nginx records a 500 internal server errror. I have no other clues about that other than the visiting IP. The error produces no output and simply stops the signup process at that point. If I comment it out, it seems that the site works just fine with the exception that no activation email is ever sent out and I need to activate users through phpmyadmin.
So I've narrowed it down to that Mail::send command.
After that error being so persistent, I tried to see what configuration my entire server was using. I found out that it was impossible to use Ipage as a mail provider so I used gmail. Now if I change the above command with the simple php mail(); command, laravel can send emails just fine. It's just that Mail::send was used to setup mailing troughout the site and I'd prefer to use that. I don't even know how to convert the Mail::send to mail();
I have setup the .env file with the settings and the OTP of gmail as an smtp provider.
MAIL_MAILER=smtp
#MAIL_HOST=smtp.ipage.com
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
#[email protected]
[email protected]
#MAIL_PASSWORD=****************
MAIL_PASSWORD=*****************
MAIL_ENCRYPTION=tls
#[email protected]
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
I have only included the current .env setting that includes the configuration for gmail as SMTP. Removed sensitive information. Of course my domain is not "domain.com"
I've also setup a failover in 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' => [
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'postmark',
],
],
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
/*'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', '[email protected]'),
'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'),
],
],
];
So this is my Standpoint of status at the moment. I will try to get mail(); working properly so that sign ups may resume but I'd really like to figure out how to make Mail:send to work again.
Any idea will be hot...
@escozul move the things that you have in env() into config() elements
add the following into your config\mail.php file
'sxm_mail_noreply' => env('SXM_MAIL_NOREPLY'),
'sxm_site_name' => env('SXM_SITE_NAME'),
and then change your invite code to use config
Mail::send(['html' => 'emails.sxm_user_activation'], $emaildata , function ($message) use ($emaildata) {
$message->from(config('mail.sxm_mail_noreply'), config('mail.sxm_site_name'));
$message->to($emaildata['email'], config('mail.sxm_site_name'))->subject(config('mail.sxm_site_name').': Account Activation');
});
now your settings should come from config files
remember to re-cache the config
Please or to participate in this conversation.