[英]How to send Email in Laravel using Mailgun?
我正在尝试在我的本地主机上发送一些测试电子邮件,但我收到了此错误消息。 我不确定这个错误与什么有关:
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 email 地址,但我仍然收到此错误。
.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);
}
联系邮箱.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>
您不能从您想要的任何域发送 email(在本例中为 @gmail.com 或 @hotmail.com)。 您只能从您在 mailgun 中授权的域发送。 这是对垃圾邮件发送者的保护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.