【问题标题】:Laravel Mail::send returns zero with no specific error in Mail::failures()Laravel Mail::send 在 Mail::failures() 中返回零且没有特定错误
【发布时间】:2017-07-12 09:14:59
【问题描述】:

我正在使用smtp 驱动程序,这是我在 laravel 5.2 中发送电子邮件的代码:

public function Sendmail()
{
    $data["mail_message"] = "Hello!";
    if(Mail::send('Emails.email', $data, function($message)
    {
        $message->from('webmaster@example.com', Input::get('name'));

        $message->to('amirhasan.hesam@gmail.com')->subject('Welcome to My Laravel app!');
    }))
    {
        return "success";
    }
    else
    {
        return Mail::failures();
    }
}

Mail::failures() 返回["amirhasan.hesam@gmail.com"] 没有具体错误!

这是我在 mail.php 上的配置:

return [

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', '*******'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => "****@*****", 'name' => "Diling"],
'encryption' => env('MAIL_ENCRYPTION', ''),
'username' => env('*****@*****'),
'password' => env('*************************'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

];

我现在正在使用 xamp 来测试电子邮件。有什么想法吗?

【问题讨论】:

  • 您在日志文件中得到了什么?他们在这个目录/project/storage/logs/
  • 即使我也有同样的问题。 laravel 日志中没有错误,并且 Mail::failures() 仅返回我们发送电子邮件的邮件 ID。

标签: php laravel email laravel-5


【解决方案1】:

你只需要使用 Mail 门面

use Illuminate\Support\Facades\Mail;

【讨论】:

    【解决方案2】:

    我在使用 mail::send 中的变量时遇到了麻烦......而且我也不确定 mail::send 是否返回布尔值或类似的......我使用过类似我过去写下的东西。

       $nameSend = Input::get('name');
        Mail::send('Emails.email', $data, function($message) use ($nameSend){
            $message->from('webmaster@example.com', $nameSend);
            $message->to('amirhasan.hesam@gmail.com')->subject('Welcome to My Laravel app!');
        });
    

    。 .

    if( count(Mail::failures()) > 0 ) {
    
      $output = "There was one or more failures. They were: \n";
    
      foreach(Mail::failures as $email_address) {
         $output = $output. $email_address ."\n";
      }
     return $output;
    }
    return "Success!";
    

    【讨论】:

    • 我认为问题不在于输入类型!事实上Mail::send 应该发送 1 如果发送成功或者 0 如果发送不成功。在我的情况下,它返回 0,对于 Mail::failures(),它返回您的代码:There was one or more failures. They were: amirhasan.hesam@gmail.com 实际上我真的需要知道它为什么会失败!!
    • 你检查过 laravel 日志吗?有时电子邮件发送失败,这是因为连接到 smtp 时出错
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 2015-04-11
    • 2023-03-27
    • 2011-07-26
    相关资源
    最近更新 更多