Laravel 4 Mail中的'From'字段:: send()

时间:2021-08-07 18:13:50

I am creating some booking system and have HTML form in which user enter his email (and other stuff). I would like to get email as if user has send it from his email address, but my Gmail always shows that I have sent it (i.e. sender email address is same as 'username' from app/config/mail.php = XYZ@gmail.com).

我正在创建一些预订系统,并有HTML表单,用户可以在其中输入他的电子邮件(以及其他内容)。我想收到电子邮件,好像用户已通过他的电子邮件地址发送邮件,但我的Gmail始终显示我已发送邮件(即发件人电子邮件地址与app / config / mail.php = XYZ @ gmail中的'用户名'相同.COM)。

This is Send::mail() method I am using

这是我正在使用的Send :: mail()方法

Mail::send('reservation-email', ['data' => $data], function($message) use ($data) {
    $message->from($data['email'], $data['name']);
    $message->to('ABC@gmail.com', 'ABC')->subject($data['subject']);
});

This is my app/config/mail.php

这是我的app / config / mail.php

return array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 587,
    'from' => array('address' => null, 'name' => null),
    'encryption' => 'tls',
    'username' => 'XYZ@gmail.com',
    'password' => 'XYZ_password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
);

I found out that I could use replyTo

我发现我可以使用replyTo

Mail::send('reservation-email', ['data' => $data], function($message) use ($data) {
    $message->from($data['email'], $data['name']);
    $message->to('ABC@gmail.com', 'ABC')->subject($data['subject']);
    $message->replyTo($data['email'], $data['name']); // <--------------------
});

but then I do not know what is the purpose of 'from' field?

但后来我不知道'from'字段的目的是什么?

Thank you in advance!

先感谢您!

1 个解决方案

#1


Maybe you are confuse of the purpose of 'from' and 'replyTo'.

也许你会混淆'from'和'replyTo'的目的。

'from' will show to your users where they received email from (It can be set in your Mail::send method in each email or in your app/config/mail.php to apply to all emails).

'from'将向您的用户显示他们收到的电子邮件(可以在每封电子邮件或您的app / config / mail.php中的Mail :: send方法中设置,以应用于所有电子邮件)。

'replyTo' will define which address that users would send their email to when they click 'reply' button.

'replyTo'将定义用户在点击“回复”按钮时向其发送电子邮件的地址。

#1


Maybe you are confuse of the purpose of 'from' and 'replyTo'.

也许你会混淆'from'和'replyTo'的目的。

'from' will show to your users where they received email from (It can be set in your Mail::send method in each email or in your app/config/mail.php to apply to all emails).

'from'将向您的用户显示他们收到的电子邮件(可以在每封电子邮件或您的app / config / mail.php中的Mail :: send方法中设置,以应用于所有电子邮件)。

'replyTo' will define which address that users would send their email to when they click 'reply' button.

'replyTo'将定义用户在点击“回复”按钮时向其发送电子邮件的地址。