为什么邮件laravel在登台服务器上不起作用? [英] Why mail laravel not working on the staging server?
问题描述
我尝试在我的本地主机上工作
I try on the my localhost, it works
但是,如果我在登台服务器上尝试,它将无法正常工作
But if I try on the staging server, it does not works
我的控制器是这样的:
<?php
use Illuminate\Support\Facades\Mail;
use App\Mail\OrderReceivedMail;
...
class PurchaseController
{
...
public function test() {
$order = $this->order_repository->find(416);
$user = $this->user_repository->find(1);
Mail::to($user)->send(new OrderReceivedMail($order, $order->store));
}
}
我的邮件是这样的:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class OrderReceivedMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public $order;
public $store;
public function __construct($order, $store)
{
$this->order = $order;
$this->store = $store;
$this->subject('subject');
}
public function build()
{
$mail_company = explode(',',config('app.mail_company'));
// dd($mail_company, $this->order->number, $this->store->name, 'test');
return $this->view('vendor.notifications.mail.email-order',['number'=>$this->order->number, 'store_name' => $this->store->name])->bcc($mail_company);
}
}
我尝试添加此内容:
dd($mail_company, $this->order->number, $this->store->name, 'test');
通过邮件
如果在我的本地主机中,则显示dd的结果
If in my localhost, the result of dd show
但是如果在登台服务器中,则不显示dd的结果
But if in the staging server, the result of dd not show
如果登台服务器似乎未运行此语句,则:
Seems if the staging server, it does not run this statement :
Mail::to($user)->send(new OrderReceivedMail($order, $order->store));
我该如何解决这个问题?
How can I solve this problem?
推荐答案
打开config/mail.php,.env文件,并将您的电子邮件驱动程序设置为波纹管",
open config/mail.php, .env files and set your email driver as mail as bellow,
'driver' => env('MAIL_DRIVER', 'mail'), //you must set it in env file too
然后,您可以像下面这样发送电子邮件,请注意,emails.admin.member是电子邮件模板的路径,在示例代码中,laravel将在路径resources\views\emails\admin\member.blade.php
then you can send emails like bellow, note that emails.admin.member, is the path to your email template, in the example code, laravel will look for a blade template in the path, resources\views\emails\admin\member.blade.php
Mail::queue('emails.admin.member', $data, function($message) {
$message->subject("A new Member has been Registered" );
$message->from('noreply@mydomain.net', 'Your application title');
$message->to('yourcustomer@yourdomain.com');
});
或
Mail::send('emails.admin.member', $data, function($message) {
$message->subject("A new Member has been Registered" );
$message->from('noreply@mydomain.net', 'Your application title');
$message->to('yourcustomer@yourdomain.com');
});
这篇关于为什么邮件laravel在登台服务器上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!