Laravel - Gmail SMTP,不通过地址发送邮件

时间:2014-10-31 16:14:20

标签: php email laravel laravel-4

我将我的网站配置为通过gmail的SMTP发送邮件。我的websiite在laravel - 4框架中运行。以下是config>> mail.php

中的代码
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'tls',
'username' => 'xxx@somedomain.com',
'password' => 'xxxxxx',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false

这是关于我如何发送邮件的代码示例

$from = 'sender@somedomain.com';

$mail = Mail::send('mailer_template', ['any_data' => $data], function ($msg) use ($from, $from_name, $to_email, $subject, $attach) {
    $msg->from($from,$from_name);
    $msg->to($to_email);
    $msg->subject($subject);
    $msg->attach($attach);
  });

当我发送邮件时,邮件正在发送。但它是从 - ' xxx@somedomain.com'发送的。我希望通过来自variabble的$发送电子邮件。而来自地址将在不同的地方发生变化。我不知道如何配置它。任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

您是否访问过此网址?如果没有,请转到此处按照说明操作,然后尝试使用生产服务器上的应用程序再次登录。

https://accounts.google.com/displayunlockcaptcha

答案 1 :(得分:0)

尝试以这种方式解决它。请记住。
此处密码不是强制性的。
对加密字段保持空白。
使用smtp-relay.gmail.com。

return array(
     'driver' => 'smtp',
     'host' => 'smtp-relay.gmail.com',
     'port' => 25, //25, 465 or 587
     'from' => array('address' => 'xxx@gmail.com', 'name' => 'myname'),
     'encryption' => '',
     'username' => 'xxx@gmail.com',
     'password' => '',
     'sendmail' => '/usr/sbin/sendmail -bs',
     'pretend' => false,
  );

答案 2 :(得分:0)

这似乎不可行,因为SMTP(gmail)仅使用电子邮件中的一个(其详细信息已添加到config / env中)。在您的情况下,无论何时发送邮件,邮件都是通过-'xxx @ somedomain发送的.com”。

相关问题