Laravel - 无法从网站向网络服务器发送电子邮件

Laravel - Unable to send Email to webserver from website

我正在尝试通过我的联系人发送邮件,但出现此错误:

Swift_TransportException (550) Expected response code 250 but got code "550", with message "550-Your FROM address ( test@email.com , test@email.com ) must match your 550-authenticated email user ( email@example.ro ). Treating this as a spoofed 550 email. "

我的 .ENV 配置:


MAIL_HOST=mail.exemple.ro

MAIL_PORT=465

MAIL_ENCRYPTION=ssl

MAIL_PASSWORD=my pass

MAIL_USERNAME=email@exemple.ro

MAIL_DRIVER=smtp

FROM_ADDRESS=email@exemple.ro

我的控制器:

{
    $validator = Validator::make($request->all(), [
        'firstName' => 'required',
        'lastName' => 'required',
        'email' => 'required',
        'services' => 'required',
        'message' => 'required',
    ]);
    if ($validator->fails()) {
        return redirect('en/404')
            ->withErrors($validator)
            ->withInput();
    }

    $form = $request->all();
    $message->success('The message was successfully send!');

    Mail::send('email/contact-form', compact('form'), function ($email_message) use ($form) {

        $email_message->subject($form['services']);
        $email_message->from($form['email']);
        $email_message->to('email@example.ro');

    });
    return back();
}

如果我尝试使用 email@exemple.ro 编写输入电子邮件,我没有收到任何错误,但是当我尝试输入 gmail 或其他电子邮件时,我收到上述错误。

请帮忙!

你在这里弄乱了你的代码

只需替换

中的代码
Mail::send('email/contact-form', compact('form'), function ($email_message) use ($form) {

    $email_message->subject($form['services']);
    $email_message->from($form['email']);
    $email_message->to('happy@greenfab.ro');

});

到下面这个

Mail::send('email/contact-form', compact('form'), function ($email_message) use ($form) {

    $email_message->subject($form['services']);
    $email_message->from(env('MAIL_USERNAME'),$form['email']);
    $email_message->to(env('MAIL_USERNAME'));
});

您在 fromto 中混淆了代码。因为您只能在 from 中输入电子邮件,它可以在端口 [=33= 上向您的 MAIL_HOST 服务器进行身份验证],这就是为什么您在输入电子邮件地址时不会收到任何错误消息的原因。

希望对您有所帮助。