【问题标题】:How to send Email in Laravel using Mailgun?如何使用 Mailgun 在 Laravel 中发送电子邮件?
【发布时间】:2020-05-25 04:41:43
【问题描述】:

我正在尝试在我的本地主机上发送一些测试电子邮件,但我收到了此错误消息。我不确定这个错误与什么有关:

exception: "Swift_TransportException"
file: "/Applications/XAMPP/xamppfiles/htdocs/highrjobsadminlte/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php"
line: 457
message: "Expected response code 250 but got code "550", with message "550 5.7.1 Relaying denied"

起初我在那里有我的gmail地址,我用谷歌搜索了错误,它说点击这个链接https://accounts.google.com/DisplayUnlockCaptcha来启用帐户访问,但这没有用。现在我正在尝试我的 hotmail 电子邮件地址,但我仍然收到此错误。

.env 文件:

MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandboxb38d58a016fc4f03a4b190ac96bf5080.mailgun.org
MAILGUN_SECRET=xxx
MAIL_FROM_ADDRESS=my hotmail email address here
MAIL_FROM_NAME="Highr Jobs Inc. - Support Team"

ContactFormController.php:

public function submit(Request $request) {

        $this->validate($request, [
            'name' => 'required|string',
            'email' => 'required|email',
            'message' => 'required',
        ]);

        $contact = [];

        $contact['name'] = $request->get('name');
        $contact['email'] = $request->get('email');
        $contact['subject'] = $request->get('subject');
        $contact['msg'] = $request->get('msg');

        // Mail Delivery logic goes here
        Mail::to(config('mail.from.address'))->send(new ContactEmail($contact));

        return response()->json(null, 200);
    }

ContactEmail.php:

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ContactEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $contact;
    /**
     * Create a new message instance.
     *
     * @return void
     */

    public function __construct($contact)
    {
        //
        $this->contact = $contact;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
            //      ->view('view.name');
            ->to(config('mail.from.address'))
            ->subject('Thank you for contacting our Technical Support Department!')
            ->view('emails.contact');
    }
}

联系方式.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Title of the document</title>
</head>

<body>


Name: {{ $contact['name'] }} <br>

E-mail: {{ $contact['email'] }} <br><br>

Message: {{ $contact['msg'] }}


{{--<h1>{{$title}}</h1>--}}

{{--<p>{{$content}}</p>--}}

</body>

</html>

【问题讨论】:

  • 您是否检查以确保发送电子邮件的@domain 已配置?你在 Windows 服务器上工作吗?

标签: laravel mailgun


【解决方案1】:

您不能从任何您想要的域(在本例中为 @gmail.com 或 @hotmail.com)发送电子邮件。您只能从您在 mailgun 中授权的域发送。 这是对垃圾邮件发送者的保护。

【讨论】:

    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 2021-01-01
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 2021-03-09
    • 2015-06-20
    相关资源
    最近更新 更多