我有一个注册页面,我想实现手动发送欢迎邮件和验证邮件。我使用mailtrap作为我的邮件主机。我像这样设置.env的邮件块
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=2c13ecf1f27070
MAIL_PASSWORD=6f6562df21bc72
MAIL_ENCRYPTION=tls
我有一个邮件验证文件:
class MailVerification extends Mailable
{
use Queueable, SerializesModels;
public $data;
public function __construct($data)
{
//
$this->data = $data;
}
public function envelope()
{
return new Envelope(
subject: 'Mail Verification',
);
}
public function build()
{
$subject = 'Mail Verification';
return $this->view('emails.index')
->subject($subject);
}
}
从我的UserController我想火邮件一旦注册成功;所以我的UserController看起来像:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Listing;
use App\Models\Company;
use Dotenv\Parser\Value;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Mail;
use App\Mail\MailVerification;
class UserController extends Controller
{
//show sign up form
public function create(User $user){
return view('users.signup');
}
//Store form fields to database
public function store(Request $request){
$chkUser = User::where('email', '=', $request->input('email'))->first();
if ($chkUser) {
return 0;
}else{
$user = new User;
$user->firstname = $request->fname;
$user->lastname = $request->lname;
$user->email = $request->email;
$user->image = 'storage/profile_images/placeholder.png';
if ($request->has('subscribe')) {
$user->subscribe = 'subscribed';
}else {
$user->subscribe = 'unsubscribed';
}
$user->password = bcrypt($request->password);
$user->save();
auth()->login($user);
$data = [
"firstname" => $request->fname,
"email" => $request->email
];
Mail::to($request->email)->send(new MailVerification($data));
return 1;
}
}
}
我创建了第一个用户帐户,它成功地发送了邮件,x1c 0d1x。但是,随后的邮件根本没有送达,我只看到他们在我的邮件陷阱收件箱。我还注意到,发件人在邮件中的ID显示Laravel。
2条答案
按热度按时间8hhllhi21#
1.在.env文件中设置
MAIL_FROM_NAME
以更改名称Laravel。1.需要从您的SMTP主机面板检查SMTP传送或失败的消息。可能是IP块/ SPF、DKIM故障。
fv2wmkja2#
您可以使用服务mail tester查找SMTP服务器问题。