Laravel 5 Mail - Gmail - AbstractSmtpTransport.php第399行:未初始化的字符串偏移量:3

时间:2016-12-16 18:11:02

标签: laravel email gmail

所以我很难在收到邮件时遇到相当困难,而且我没有找到类似的解决方案。我正在尝试使用SMTP从我的网站通过Gmail发送基本电子邮件。一切似乎都是正确的。谢谢你的帮助

•我的帐户是xxx@gmail.com。我已在此帐户上设置了两步验证。 xxx@gmail.com帐户的密码为a123
•我试图从我的电子邮件marketing@y.com发送它。对于xxx@gmail.com •在gmail-settings-account下导入 - 发送邮件为 •我有 o营销 - 别名。
o邮件通过以下方式发送:smtp.gmail.com
o端口587上的安全连接 o使用TLS •点击编辑信息 - 姓名:
o市场营销 o电子邮件地址:marketing@y.com •单击下一步 - 编辑电子邮件地址 - 通过SMTP服务器发送邮件 o配置要通过SamsSocial.com SMTP服务器发送的邮件了解更多信息 o您当前正在使用:使用TLS在端口587上进行安全连接 o要进行编辑,请在下面调整您的偏好。 o SMTP服务器:smtp.gmail.com o端口:用户名:xxx@gmail.com o密码:OTHERPASS o使用TLS进行安全连接(推荐)

我收到以下错误,并且花费了相当长的时间

AbstractSmtpTransport.php第399行中的ErrorException: 未初始化的字符串偏移量:3 在AbstractSmtpTransport.php第399行 at HandleExceptions-> handleError(' 8','未初始化的字符串偏移:3',' C:\ wamp \ www \ d \ vendor \ swiftmailer \ swiftmailer \ lib \ classes \ Swift \ Transport \ AbstractSmtpTransport.php',' 399',array(' seq' =>' 8','响应&# 39; =>'�334VXNlcm5hbWU6L',' line' =>' L'))AbstractSmtpTransport.php第399行 在AbstractSmtpTransport.php第277行的Swift_Transport_AbstractSmtpTransport-> _getFullResponse(' 8') 在EsmtpTransport.php第270行的Swift_Transport_AbstractSmtpTransport-> executeCommand(' AUTH LOGIN',数组(' 334'),array()) 在LoginAuthenticator.php第40行的Swift_Transport_EsmtpTransport-> executeCommand(' AUTH LOGIN',array(' 334'))

控制器

public function sendEmailReminder()
    {
        $user = User::findOrFail(1);
        // dd(Config::get("mail"));

        Mail::send('admin.marketing.emails.test', ['user' => $user], function ($m) use ($user) {
           //i've had this with and without the from
            $m->to('test@yahoo.com', 'peter')->subject('This is how we do it');
        });
        return redirect('admin/marketing');

    }

Test.blade.php

Hi {{$user['name']}}. this is the first email we've sent

配置/ mail.php

<?php

return [
    'driver' =>  'smtp',
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'Marketing@t.com', 'name' => 'Marketing'],
    'encryption' => 'tls',
    'username' => env('MAIL_USERNAME',xxx@gmail.com'),
    'password' => env('MAIL_PASSWORD','OTHERPASS’),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

.ENV

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxx@gmail.com
MAIL_PASSWORD=OTHERPASS
MAIL_ENCRYPTION=tls

当我做dd(Config :: get(&#34; mail&#34;)); - 我得到以下看似正确的

array:9 [▼
  "driver" => "smtp"
  "host" => "smtp.gmail.com"
  "port" => "587"
  "from" => array:2 [▼
    "address" => "Marketing@y.com"
    "name" => "Marketing"
  ]
  "encryption" => "tls"
  "username" => "xxx@gmail.com"
  "password" => "OTHERPASS"
  "sendmail" => "/usr/sbin/sendmail -bs"
  "pretend" => false
]

1 个答案:

答案 0 :(得分:0)

错误可能会产生误导,但实际上是因为针对gmail smtp服务器的身份验证产生了意外输出。 Google已经改变了授权适用于客户端应用的方式。

现在有必要为代表您访问邮件或日历的应用程序检索应用程序密码,并使用该应用程序密码而不是您用于网络的常用密码。 更多信息:https://support.google.com/accounts/answer/185833?hl=en