我想在我的本地主机上发送一些测试邮件, 但是我收到了这个错误信息. 我不知道这个错误与什么有关:
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');
}
}
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>
你不能从任何你想要的域名发送邮件(在本例中是@gmail.com或@hotmail.com)。你只能从你在mailgun中授权的域名发送邮件,这是为了防止垃圾邮件发送者。