邮件php函数在laravel中获取错误

时间:2018-01-16 13:59:40

标签: php laravel laravel-5

我使用邮件功能覆盖重设密码验证。

public function resetPassword(Request $request){
    $new_password = rand(120400, 940490);
    $email=$request->input("email");
    $user = new User();
    $count = $user -> where('email',$email) -> count();
    if ($count == 0){
        $meta = $api_meta->metaData(false,"Email does not exist.",[],'');
        return ['meta'=>$meta];
    }
    $user = $user -> where('email',$email) -> get() -> first();


    $user -> password = bcrypt($new_password);
    $user -> save();

    $to      = $email;
    $subject = 'user message';
    $message = "
    Your new password is : $new_password
    ";
    $headers = 'From: ' .$email. "\r\n";


    mail($to, $subject, $message, $headers);

}

在Router.php中,我修改了:

$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');

为:

$this->post('password/email', 'UserController@resetPassword')->name('password.email');

我认为一切都没问题,但我收到了错误:

  

无法发送没有发件人地址的邮件

1 个答案:

答案 0 :(得分:0)

确保您已在from

中定义config/mail.php
'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],

如果您没有对其进行编辑,请将发件人电子邮件和姓名添加到.env

MAIL_FROM_ADDRESS=me@example.com
MAIL_FROM_NAME=MyName