CakePHP 电子邮件从 SMTP 上的地址更改

CakePHP Email changing from address on SMTP

我有此电子邮件配置,可通过我们的 Google Apps 企业帐户通过 SMTP 发送。

class EmailConfig {
    public $default = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'myemail@mygmaildomain.com',
        'password' => 'secret_password',
        'transport' => 'Smtp'
    );
}

当我发送电子邮件时:

$email = new CakeEmail('default');
$email->from('no-reply@mygmaildomain.com', 'My App');
$email->to(array('recipient@mygmaildomain.com' => 'Recipient Name'));
$email->subject('Test Email');
$email->emailFormat('html');
$email->send();

电子邮件已送达,但它发送的邮件来自:myemail@mygmaildomain.com 而不是 no-reply@mygmaildomain.com

是否还有我需要使用的其他设置,或者这是不可能的?

编辑:

我已经尝试了下面评论中提供的解决方案,但它仍然无法使电子邮件来自 no-reply

当使用 Google 的 SMTP 服务器时,from header 被忽略。

$email->from('no-reply@mygmaildomain.com', 'My App'); //Ignored by Gmail

来自 DigitalOcean 的教程 How to use Google's SMTP server:

NOTE: Google automatically rewrites the From line of any email you send via its SMTP server to the default Send mail as email address in your Gmail or Google Apps email account Settings. You need to be aware of this nuance because it affects the presentation of your email, from the point of view of the recepient, and it may also affect the Reply-To setting of some programs.

为此,您必须在 Google 应用程序控制面板中修改邮件设置:

Workaround: In your Google email Settings, go to the Accounts tab/section and make "default" an account other than your Gmail/Google Apps account. This will cause Google's SMTP server to re-write the From field with whatever address you enabled as the default Send mail as address.