Laravel 5.5 mailgun 不发送电子邮件 - 没有错误
Laravel 5.5 mailgun not sending emails - no errors
我正在尝试使用 mailgun 发送电子邮件,但它们不会发送,我不知道为什么,因为我根本没有收到任何错误。
这是我的代码:
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));
}
确认Email.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('mailgun@sandbox1e17506823f2490ba9cc78cbbc2adb60.mailgun.org')
->view('emails.confirm');
}
}
我已经在 mailgun 中添加了我要发送到的电子邮件地址,但是它不起作用。我做错了什么或者有什么方法可以调试吗?
你的配置有误:
'mailgun' => [
'domain' => env('sandbox1e...60.mailgun.org'),
'secret' => env('key-146...419'),
],
env 函数查找具有您提供的名称和 returns 值的环境变量。您应该将其更改为环境变量的名称并在您的 .env 中定义它,或者不要使用 env 函数,但不推荐这样做。
虽然 Esteban Garcia 的答案是正确的,但我希望通过显示配置的确切外观的代码片段来改进它:
在您的 config/services.php
中,保留如下所示的配置:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
在您的 .env
文件中,这是您定义实际 mailgun 凭据的地方:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandbox1e...60.mailgun.org
MAILGUN_SECRET=key-146...419
In your laravel .env configure these things
MAIL_DRIVER=mailgun
MAIL_USERNAME=postmaster@sandboxXXXXXX.mailgun.org
MAILGUN_DOMAIN=sandboxXXXXX.mailgun.org
MAILGUN_SECRET=XXXXXXX
After that goto vendor->guzzlehttp->src->client.php find
configureDefaults() method have array name called defaults that array
have verify => true change to false
'verify' => false,
then configure mail.php
'from' => ['address' => 'youremail@gmail.com', 'name' => 'yourname'],
go to route.php and test email is working or not send simple email.
plz make sure you install laravel mail class or install using this
command composer require guzzlehttp/guzzle
use Illuminate\Support\Facades\Mail;
Route::get('/', function () {
$data = [
'title'=>'title here',
'Content'=>'simple content'
];
Mail::send('email.test',$data, function ($message){
$message->to('youremail@gmail.com', 'John Smith')->subject('Welcome!');
});
});
我正在尝试使用 mailgun 发送电子邮件,但它们不会发送,我不知道为什么,因为我根本没有收到任何错误。
这是我的代码:
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));
}
确认Email.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('mailgun@sandbox1e17506823f2490ba9cc78cbbc2adb60.mailgun.org')
->view('emails.confirm');
}
}
我已经在 mailgun 中添加了我要发送到的电子邮件地址,但是它不起作用。我做错了什么或者有什么方法可以调试吗?
你的配置有误:
'mailgun' => [
'domain' => env('sandbox1e...60.mailgun.org'),
'secret' => env('key-146...419'),
],
env 函数查找具有您提供的名称和 returns 值的环境变量。您应该将其更改为环境变量的名称并在您的 .env 中定义它,或者不要使用 env 函数,但不推荐这样做。
虽然 Esteban Garcia 的答案是正确的,但我希望通过显示配置的确切外观的代码片段来改进它:
在您的 config/services.php
中,保留如下所示的配置:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
在您的 .env
文件中,这是您定义实际 mailgun 凭据的地方:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandbox1e...60.mailgun.org
MAILGUN_SECRET=key-146...419
In your laravel .env configure these things
MAIL_DRIVER=mailgun
MAIL_USERNAME=postmaster@sandboxXXXXXX.mailgun.org
MAILGUN_DOMAIN=sandboxXXXXX.mailgun.org
MAILGUN_SECRET=XXXXXXX
After that goto vendor->guzzlehttp->src->client.php find configureDefaults() method have array name called defaults that array have verify => true change to false
'verify' => false,
then configure mail.php
'from' => ['address' => 'youremail@gmail.com', 'name' => 'yourname'],
go to route.php and test email is working or not send simple email. plz make sure you install laravel mail class or install using this command composer require guzzlehttp/guzzle
use Illuminate\Support\Facades\Mail;
Route::get('/', function () {
$data = [
'title'=>'title here',
'Content'=>'simple content'
];
Mail::send('email.test',$data, function ($message){
$message->to('youremail@gmail.com', 'John Smith')->subject('Welcome!');
});
});