简体   繁体   English

如何使用 Mailgun 在 Laravel 中发送 Email?

[英]How to send Email in Laravel using Mailgun?

I'm trying to send some test emails on my localhost, but I'm getting this error message.我正在尝试在我的本地主机上发送一些测试电子邮件,但我收到了此错误消息。 I'm not sure what this error is related to:我不确定这个错误与什么有关:

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"

At first I had my gmail address in there, I googled the error, it said to click on this link https://accounts.google.com/DisplayUnlockCaptcha to enable account access, but that didn't work.起初我在那里有我的 gmail 地址,我用谷歌搜索了错误,它说单击此链接https://accounts.google.com/DisplayUnlockCaptcha以启用帐户访问,但这不起作用。 Now I'm trying my hotmail email address and I'm still getting this error.现在我正在尝试我的 hotmail email 地址,但我仍然收到此错误。

.env file: .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: 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:联系邮箱.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');
    }
}

Contact.blade.php:联系方式.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>

You can't send email from any domain you want (in this case @gmail.com or @hotmail.com).您不能从您想要的任何域发送 email(在本例中为 @gmail.com 或 @hotmail.com)。 You can send only from domain you authorized in mailgun.您只能从您在 mailgun 中授权的域发送。 This is a protection from spammers.这是对垃圾邮件发送者的保护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM