简体   繁体   English

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

[英]Laravel - Gmail SMTP, not sending mail through - from address

I configured my website to send mails through gmail's SMTP. 我将网站配置为通过gmail的SMTP发送邮件。 My websiite is running in laravel - 4 framework. 我的网站在laravel-4框架中运行。 Below is the code in config>>mail.php 下面是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

And this is a sample of code, on how I send mail, 这是关于我如何发送邮件的代码示例,

$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);
  });

When I send a mail, the mail is being sent. 当我发送邮件时,正在发送邮件。 But it is sent from - 'xxx@somedomain.com'. 但是它是从-“ xxx@somedomain.com”发送的。 I want it to be sent through the email in $from variabble. 我希望通过$ from variabble通过电子邮件发送。 And the from address will change at different places. 并且发件人地址将在不同位置更改。 I am not sure how to configure this. 我不确定如何配置。 Any help would be appreciated. 任何帮助,将不胜感激。

Have you visited this URL yet? 您访问过此URL吗? If not, go there and follow the instructions then try to sign in again with your application on the production server. 如果不是,请去那里并按照说明进行操作,然后尝试使用生产服务器上的应用程序再次登录。

https://accounts.google.com/displayunlockcaptcha https://accounts.google.com/displayunlockcaptcha

Try to solve it this way. 尝试以这种方式解决它。 Keep it mind. 请注意。
Here password is not mandatory. 这里的密码不是必须的。
Keep blank for encryption field. 加密字段保留空白。
use smtp-relay.gmail.com. 使用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,
  );

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM