Good day!
I was able to send emails using Yii2 swift mailer fine. I’m just having trouble with one feature.
============
BACKGROUND
============
(1) I’m trying to have gmail and ymail display sender as a name instead of an email address.
(2) In order to do so, I think I need to set email header ‘From’ field to something like the line below:
‘From: DisplayName <YourName@domain.com>’
============
PROBLEM
============
(1) According to the two URL below, it is easy to do:
<—Urls Ommitted. I was not allowed to post urls.—>
(2) I think I just need to use a keyed array for setFrom() input below where they key is the Email and the value is the DisplayName:
$status['sent'] = \Yii::$app->mailer->compose(
$modelNewsletter['page'],
[
'intro' => $modelNewsletter['intro'],
'emailData' => $emailData
]
)->setFrom(
[
$ctrl['basic.adminEmail'] => $ctrl['sender.name']
]
)->setTo(
$obj['email']
)->setSubject(
$modelNewsletter['subject']
)->send();
(3) But I could not get it to work. I also tried searching this forum. But could not find relevant information.
============
DEBUGGING
============
(1) I first tried to send out real emails. But it would not work. The email sends but gmail and ymail won’t show a name for the sender.
(2) Then I try to set config/web.php to create dummy file emails instead by setting mailer.useFileTransport to TRUE.
'mailer' => [
'useFileTransport' => true,
],
This is so that I can use Yii2 debugger to view the email headers.
(3) Yii2 Debugger shows me the ff headers. Please see "From". It has no name, just an email.:
Message-ID: <c92cb0cfe23645d1463c4769f54b6dd0@www.mystartups.ph>
Date: Tue, 14 Jun 2016 03:21:47 +0000
Subject: Personalized Test
From: admin@mystartups.ph
To: zentlim@gmail.com MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=swift_v4_1465874507_0bba28970e4d1af435a481e131158cfb="
============
VERSION
============
According to my composer.lock file, I’m using the ff versions:
(1) yiisoft/yii2 2.0.5
(2) swiftmailer/swiftmailer v5.4.1
============
QUESTION
============
How do I get setFrom() to update email header so that it will use a display name with an email?