duanqiang6501 2017-04-18 13:11
浏览 46
已采纳

Laravel和Mailgun无法正常工作

Before production version I used mailtrap to test my emails and everything worked like it should be, but today I uploaded my website to a public server and decided to use mailgun, I know its not so simple like mailtrap.io, but still. Anyway I verified my account and can now send 10k emails per month. Not bad, but the thing is when I try to send an email I get a notification that the email was sent, but there is no email in any inbox.

My .env file

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=myEmail
MAIL_PASSWORD=myPassword
MAIL_ENCRYPTION=tls

My services.php file

return [

'mailgun' => [
    'domain' => env('myDomain'),
    'secret' => env('secretKey'),
],

'ses' => [
    'key' => env('SES_KEY'),
    'secret' => env('SES_SECRET'),
    'region' => 'us-east-1',
],

'sparkpost' => [
    'secret' => env('SPARKPOST_SECRET'),
],

'stripe' => [
    'model' => App\User::class,
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
],

];

One of the functions:

public function store(StoreListingContactFormRequest $request, Area $area, Listing $listing){

        Mail::to($listing->user)->queue(
            new ListingContactCreated($listing,
                $request->name,
                $request->email,
                $request->number,
                $request->message
            )
        );
        return back()->withSuccess("Teie sõnum on edukalt saadetud firmale {$listing->user->name}");
    }

Another one:

public function __construct()
    {
        $this->middleware(['auth']);
    }

    public function index(Area $area, Listing $listing){
        return view('listings.share.index', compact('listing'));
    }

    public function store(StoreListingShareFormRequest $request, Area $area, Listing $listing){

        collect(array_filter($request->emails))->each(function($email) use ($listing, $request){
            Mail::to($email)->queue(
                new ListingShared($listing, $request->user(), $request->messages)
            );
        });

        return redirect()->route('listings.show',[$area, $listing])->withSuccess('Kuulutus on jagatud edukalt!');
    }
  • 写回答

1条回答 默认 最新

  • dongzhuange2625 2017-05-05 10:57
    关注

    seems the error is here

    MAIL_USERNAME=myEmail

    MAIL_PASSWORD=myPassword

    MAIL_USERNAME should be not your email but Default SMTP Login from your domain settings page. And Default Password on the same page for MAIL_PASSWORD

    'domain' => env('myDomain'),

    here you need to enter not your site's domain but the domain you've registered on mailgun, something like mg.exmaple.com

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1