Currently, when a Laravel user verification mail is sent, the sender is hello#example.com with a name of Example. How can I modify these values without changing files in the vendor directory (e.g. php artisan vendor:publish, but what?). I´ve looked at this question, \Illuminate\Auth\Notifications\VerifyEmail.php and \Illuminate\Auth\MustVerifyEmail.php, but while a markdown template is declared (which I´ve published to my resources to tweak it a little), there´s no code which actually sends the mail with sender and sender name!?
It can be found in config/mail.php, see the snippet:
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
Add the values to your .env file and it should be good.
Related
Server: Digital Ocean
Ubuntu 16.04
Laravel 5.8
I cannot get email to send out of laravel using mailgun.com
In Digital Ocean I have all outgoing ports open on the firewall, I have the correct DNS settings in Digital ocean for TXT and MX records. I have the correct and verified DNS records on my domain registar and mailgun has a green checkmark on all
config/mail.php
return [
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => [
'address' => 'orders#domain.com',
'name' => 'Company Name'
],
'encryption' => 'tls'),
'username' => 'orders#mg.domain.com',
'password' => 'xxxxd663hd02j727bb2eefd1ea38bbe0-58bc211a-670xxxx'
];
config/services.php
'mailgun' => [
'domain' => 'https://api.mailgun.net/v3/mg.domain.com',
'secret' => 'xxxxehbe8v25g3374e5as3ff32a45995-39bc661a-4716xxxx',
],
Controller
use Illuminate\Support\Facades\Mail;
$data = [
'email' => 'email#yahoo.com',
'name' => 'Bob Smith'
];
$body_data = [
'id' => '1234'
];
Mail::send('emails.shipped', $body_data, function($message) use ($data)
{
$message->to($data['email'], $data['name'])->subject('Test Email');
});
When I change mail driver to log and then check log file it looks great. Everything looks perfect and I have used mailgun before on Laravel 5.5 with no problems.
I have also tried the new laravel build method and same issue.
I get no errors, I checked logs on apache2, no logs are appearing in mailgun and of course no email comes through in inbox or spam.
My question is, am I missing anything? What other troubleshooting can I do? Seems like my app isn't connecting to mailgun correctly.
I think that in your config/services.php the mailgun.domain should be more like
mg.domain.com (or sandboxXXXXXXX.mailgun.org if that's a dev environment), and not a url like the one you've set.
Try to put:
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
in your mailgun array.
I'm using laravel 5.8 and it's working with all default configuration
.env
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandbox8a408833ad1540e7b3a5d0151f606531.mailgun.org
MAILGUN_SECRET=92df7e85eeeaccaeae3d3b3164600666-87cdd773-8c819599
web.php
Route::get('send_test_email', function(){
Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message)
{
$message->to('your_test_email#gmail.com');
});
});
services.php
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
I struggled with this very same problem (laravel + mailgun) for a FULL DAY.
This is what ultimately solved my problem. Hope this helps!
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mail.mydomain.com
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_FROM_ADDRESS=kp#mydomain.com
MAIL_FROM_NAME='KP'
In routes/web.php:
Route::get('/tst', function(){
Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message)
{
$message->to('kp#yahoo.com', 'K P')->subject('Hello there, how are you?');
});
echo "string";
});
Note: you will need to make sure that your MAILGUN_DOMAIN is set and the MX / DNS records exist on your server / domain. This can take up to 24 hrs to propagate (sadly, the most annoying part). But these are all the settings you would need.
You may try Installing SwiftMailer library in your server.
sudo apt install -y php-swiftmailer
I have been trying to get emails to send from Laravel for the past day without success. I have been testing locally using homestead and on a live linux server environment with no luck.
I have removed email settings from the .env file. and directly added the settings in my config/mail file.
so far I have tried office 365 settings, gmail and finally maligun, none of which send an email.
my settings are below.
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'postmaster#sandbox********099b827475b585029.mailgun.org'),
'name' => env('MAIL_FROM_NAME', 'Test account'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('postmaster#sandbox****************099b827475b585029.mailgun.org'),
'password' => env('********************'),
I complete the password reset process via password/reset and it says the password reset link was sent successfully but it is never sent, the mailgun logs confirm no email was sent, the token is updated in the password_reset table
I ssh'd onto homestead and tested sending a email via mailgun using curl and this works.
if I set mail driver to SMTP I still get the same issue.
when setting the drive to 'log' the log files shows the email template etc.
any help would be appreciated.
thanks
What environment you working with? Local or production?
What kind of email you're using? Gmail or testing mail such as mailtrap?
If gmail did you active smtp from settings? Please provide more information.
Update:
let us test other ways to see if it makes any differences:
Go to your routes file web.php and comment this:
// Auth::routes();
Now add following routes:
// Authentication routes
Route::get('/login',['as'=>'login', 'uses' => 'Auth\LoginController#showLoginForm']);
Route::post('/login', ['uses'=>'Auth\LoginController#login']);
Route::get('/logout',['as'=>'logout', 'uses'=>'Auth\LoginController#logout']);
Route::get('/register', ['as' => 'register', 'uses' => 'Auth\RegisterController#showRegisterForm']);
Route::post('password/email', ['as'=>'password.email', 'uses'=>'Auth\ForgotPasswordController#sendResetLinkEmail']);
Route::get('password/reset', ['as'=>'password.request', 'uses'=>'Auth\ForgotPasswordController#showLinkRequestForm']);
Route::post('password/reset', ['as'=>'password.request', 'uses'=>'Auth\ResetPasswordController#reset']);
Route::get('password/reset/{token}', ['as'=>'password.reset', 'uses'=>'Auth\ResetPasswordController#showResetForm']);
Route::post('logout', ['as'=>'logout', 'uses'=>'Auth\LoginController#logout']);
Try and see if it works or not.
I'm trying to send mail in Laravel 5.4 project with Mailgun. I think I set the configuration correctly. But, I got this error message such as
ClientException in RequestException.php line 111:
Client error: POST https://api.mailgun.net/v3/sandboxfeb88d58f18841738b2fc81d7cbc7631.mailgun.org/messages.mime >resulted in a 401 UNAUTHORIZED response:
Forbidden
Here is my configuration:
in .env file
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandboxfeb88d58f18841738b2fc81d7cbc7631.mailgun.org
MAILGUN_SECRET=pubkey-1767e**********
in mail.php file
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'richi.htoo#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'Richi Htoo'),
],
in services.php file
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
and I wrote mail sending code in default route such as
Route::get('/', function () {
//return view('welcome');
$data = [
'title' => 'Hi student I hope you like the course',
'content' => 'This laravel course was created with a lot of love and dedication for you'
];
Mail::send('emails.test', $data, function($message){
$message->to('white.nuzzle#gmail.com', 'White Nuzzle')->subject('Hello student how are you?');
});
});
And I also installed Laravel Package "guzzlehttp/guzzle" version 6.2 to send mail.
But when I call that default home route, I got an error message as I mention above.
I can't find any solution for my error in any where including this forum "stackoverflow.com".
Can anyone help me please?
Ok found it,
In the file "vendor\laravel\framework\src\Illuminate\Mail\Transport\MailgunTransport.php", the endpoint used is US one.
As said in documentation, https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions, you have an endpoint for US and EU.
If you are european, you must use "api.eu.mailgun.net" or you get a 401.
Just change the endpoint: Laravel is powerful and they think about that. You can add an 'endpoint' key to the config/services.php/mailgun entry.
Frankly it was quite an ordeal, I made the sandbox work as following
Added authorized recipient - Apparently sandbox can't send email to
anyone, you need to add them as authorized recipient.
Use proper credentials in .env File added MAILGUN_DOMAIN and MAILGUN_SECRET too as services.php uses them. Remember MAILGUN_SECRET is the private key and starts with key-, don't use public key here
Put
MAIL_DRIVER=mailgun MAIL_HOST=smtp.mailgun.org MAIL_PORT=587 MAIL_USERNAME=postmaster#sandboxcc*****************.mailgun.org MAIL_PASSWORD=****************** MAIL_ENCRYPTION=tls
!!!MOST IMPORTANT!!!! RESTART YOUR SERVER to load the new .env file.
If you are not using the United States Mailgun region, you can define your region's endpoint in the services configuration file:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.eu.mailgun.net'),
],
Alternatively, one can define the MAILGUN_ENDPOINT in the .env file:
MAILGUN_ENDPOINT="api.eu.mailgun.net"
Make sure to check your credentials for the mailgun, make sure that those are correct.
Dont copy the Public Validation Key.
please copy the Private API Key
Default Mail Driver: Mailgun
MAILGUN_DOMAIN=*your-domain*.mailgun.org
MAILGUN_SECRET=pubkey-*your-public-key*
Default Mail Driver: SMTP
MAIL_USERNAME=postmaster#*your-domain*.mailgun.org
MAIL_PASSWORD=*your-password*
Don't forget to php artisan config:clear
I had the same issue. Check your DNS settings in the Mailgun Sending domain checklist. I found I could not get an EU MG setting to work so I suggest you use a US MG server
Ok, I just want to summarize what I had to do to make Mailgun work in Laravel 8.
1. Install guzzle
composer require guzzlehttp/guzzle
2. EU or US?
I'm from EU. The Laravel Doc for Mailgun says to configure mailgun for usage in EU. This is WRONG if you're using the sandbox because it is located in the US apparently. I have a small US flag next to my sandbox url and it took me ages to figure this out.
If you want to use the sandbox put this into \config\services.php:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
],
If you want to use a domain that is registered for EU you will need to make this change:
'endpoint' => env('MAILGUN_ENDPOINT', 'api.eu.mailgun.net'),
If you put the wrong region, your log should throw 401 UNAUTHORIZED response
3. Authorize Recipients
If you're using the sandbox you need to authorize recipients. Go to your mailgun account and to your sandbox domain and authorize recipients in the email field. If you try to send an email to non-authorized recipients your log should throw an 403 FORBIDDEN response
4. Default Mailer
If you want mailgun to be your default mailer you can change this in your \config\mail.php:
'default' => env('MAIL_MAILER', 'mailgun'),
5. Credentials
These credentials made it work for me, hopefully they will make it work for you too. Put them in .env:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org
MAILGUN_SECRET=2dfXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAILGUN_SECRET is your private api key which can be found when go to your mailgun account and click on your profile logo -> api keys.
MAILGUN_DOMAIN is your (I believe currently used) domain and can be accessed in your mailgun account either through the dashboard or through sending->domains in the navpanel. The only not messy reference field for your domain seems to be in sending->overview-> select SMTP and copy the end part of the Username field (without postmaster#)
I hope this saves time for someone because it took forever to get it to work.
Personally I never got the sandbox account to work. I just did this a little over a month ago. Sandbox never worked, but the live account I created did. Try switching to the live account and let me know if that works for you.
Just go to the config folder. and made some changes..
'mailgun' => [
'domain' => env('your_domainxxxxxxx.mailgun.org'),
'secret' => env('key-xxxxxxxx_private_API_keyxxxx'),
],
error will be resolved.
In case if you use API base mailgun, check if the domain exists.
I removed my testing domain and after it tried to send a new email message from that domain. I got 401 error.
I had the same problem in Symfony. Yes, it's not Laravel but they're close.
In .env file I had
MAILER_DSN=mailgun://KEY:DOMAIN#default
The error disappeared after I changed it to
MAILER_DSN=mailgun://KEY:DOMAIN#default?region=eu
I am looking around for some answers to my problem. I really do not know what in my settings or code is wrong but i can't make the sending of email work.
Here is my mail.php values
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => 'here is my email', 'name' => 'Some name here'),
'encryption' => 'tls',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
Here is the services.php
'mailgun' => array(
'domain' =>'my domain here' ,
'secret' => 'my secret key here',
),
Here is my code for Sending.
$data = array(
'msg' => 'You have successfully registered ',
'url' => 'someURL'
);
try{
Mail::send('emails.REGISTRATION_SUCCESS', $data, function($message){
$message->from('admin#something.com', 'y System');
$message->to('myemail#gmail.com')->subject(' Registration Successful!');
});
}catch(Exemption $e){echo $e->getMessage();}
echo 'hello';
I am having this error whenever I run the code.
Class 'GuzzleHttp\Client' not found
I really do not know where in this code i am wrong. I am currently stuck right now. it still not sending any email. I really dont know now. please hep me. I am looking at some tutorials and almost same question post but nothing is working. any suggestions?
From the Laravel mail documentation:
Driver Prerequisites
The API based drivers such as Mailgun and SparkPost are often simpler and faster than SMTP servers. If possible, you should use one of these drivers. All of the API drivers require the Guzzle HTTP library, which may be installed via the Composer package manager:
composer require guzzlehttp/guzzle
in you composer.json file add this "guzzlehttp/guzzle": "~5.3|~6.0" in require portion then composer update for more info click here
or just in your terminal on the laravel root folder run composer require "guzzlehttp/guzzle": "~4.0"
Just do as #Martin suggested
$ composer require guzzlehttp/guzzle
from command-line on your project path.
This will install the required packages. Also refer guzzle github link
Just in case, you are doing this directly on production (which is really very dangerous), you may follow #bashar's answer.
I've a laravel app nad I've been testing it with gmail smtp server and It was working in my system's localhost but then I deployed it on server (blue host) and change the configuration and still the app thinks that is sending emails and it's not giving me errors but no email is delivered to corresponding email addresses....
Here's my mail.php in app folder:
return array(
'driver' => 'smtp',
'host' => 'mail.mash-up.fi',
'port' => 26,
'from' => array('address' => 'registration#mash-up.fi', 'name' => 'Admin'),
'encryption' => 'tls',
'username' => '************',
'password' => '******',
'sendmail' => '/usr/bin/sendmail -bs',
'pretend' => false,
);
where I'm doing wrong?
any help is appreciated
If you are using the BH DNS(ns1.bluehost...), then check to see that the $from address is an existing email in your BH account.
(go to your CP /domain manager and use whois info to find that out.)
or.....
maybe, you migrated the source code, but did you transfer your domain name to BH, or is it pointing to BH servers (DNS)
In that case your site is not using the BH mail servers.
example :your site content could be on BH, but if it is registered somewhere else and the DNS is not ns1.bluehost.com..etc, then your domain might be using url forwarding or framing (to bring visitors to the BH location). but your mail functions may be handled by the registrar's
hope this is not too confusing
it is also helpfull if you post your domain name here and others can help figure out as well.
Please try to check the spam folder of where your sending to. If there is nothing, make sure your "from" is truly your bluehost email account your using to send the email. If the actual sender doesn't match the "from" of the e-mail many mail clients will ignore it entirely (like hotmail), but gmail will put it in the spam folder with a warning.
The host should be your bluehost box I think. In fact on cpanel, go to email, where you create accounts. Then click on "More", select "Configure Email Client", scroll down. You will see the host name, and port.
TTL/SSL would likely need port 465, I am guessing (I use the latter, not the former like you).
Open up the laravel.logs file inside of storage > logs. It should help give you some idea of what the problem might be.