我有以下代码可以向会议组织者发送电子邮件:
$user = Auth::user();
$conference = Conference::find($id);
$message = $request->message;
$subject = $request->subject;
Mail::to($conference->organizer_email)
->send(new UserNotification
($conference, $user, $message, $subject));
使用此代码,可以将电子邮件发送到会议组织者,这是正确的。问题是,发件人地址中的发件人地址中没有显示已验证用户的电子邮件,而是显示了MAIL_USERNAME中.env文件中配置的电子邮件。
UserNotification:
class UserNotification extends Mailable
{
use Queueable, SerializesModels;
public $conference;
public $user;
public $message;
public $subject;
public function __construct(Conference $conference, User $user, $message, $subject)
{
$this->conference = $conference;
$this->user = $user;
$this->message = $message;
$this->subject = $subject;
}
public function build()
{
// shows the auth user email so why the received email is
// appears that was sent from the email
// set in MAIL_USERNAME in .env file
// instead of appear the auth user email?
dd($this->user->email);
return $this->from($this->user->email)->markdown('emails.userNotification', [
'message' => $this->message,
'subject' => $this->subject
]);
}
}
答案 0 :(得分:0)
编辑您的用户通知
class UserNotification extends Mailable
{
use Queueable, SerializesModels;
public $conference;
public $user;
public $message;
public $subject;
public function __construct(Conference $conference, User $user, $message, $subject)
{
$this->conference = $conference;
$this->user = $user;
$this->message = $message;
$this->subject = $subject;
}
public function build()
{
return $this
->from($this->user->email)
->to($conference->organizer_email)
->markdown('emails.userNotification', [
'message' => $this->message,
'subject' => $this->subject
]);
}
}
答案 1 :(得分:0)
您无法将发件人电子邮件传递给gmail的smtp,因为它将覆盖标头以根据您帐户的配置来设置发件人的电子邮件。
您可以更新帐户的配置以添加其他发件人:https://support.google.com/mail/answer/22370?hl=en
否则,您可以为您的应用专门创建另一个Gmail帐户。
appname@gmail.com
否则,您将不得不使用其他邮件驱动程序。