如何重写或设置cakePHP电子邮件组件中的返回路径?

发布于 2024-08-19 08:17:16 字数 313 浏览 3 评论 0原文

我正在使用 cakePHP 电子邮件组件从我的应用程序发送邮件。现在返回路径有类似 [email protected]

我该如何设置或者在使用 cakePHP 组件时重写电子邮件中的 Return-Path 值?

我知道在 PHP 中通过“邮件”发送邮件时该怎么做,但 cakePHP 电子邮件组件似乎缺少这样的功能......或者我错过了什么? :)

I'm using the cakePHP email component for sending mails from my application. Now the return-path has something like [email protected]

How can I set or rewrite the Return-Path value in emails when using the cakePHP Component?

I know how to do it when sending mails via 'mail' in PHP but the cakePHP email component seems to missing such a feature... or am I missing something? :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月流歌 2024-08-26 08:17:16

CakePHP 2 中(电子邮件组件很大程度上被 CakeEmail 类),您可以在 /app/Config/email.php 中执行此配置:

class EmailConfig {
    public $email = array(
        ...
        // The next line attempts to create a 'Return-path' header
        'returnPath' => '[email protected]',

        // But in some sendmail configurations (esp. on cPanel)
        // you have to pass the -f parameter to sendmail, like this
        'additionalParameters' => '[email protected]',
        ...
    );
}

或者如果您只需要为一封电子邮件执行此操作,类似这样的操作应该可以...

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('MyConfig');
$email->from(...)
      ->to(...)
      ->subject(...)
      ->returnPath('[email protected]')
      // Haven't tested this next line, but may possibly work?
      ->config(array('additionalParameters' => '[email protected]'))
      ->send();

In CakePHP 2 (where the Email Component is largely replaced by the CakeEmail class), you can do this configuration inside /app/Config/email.php:

class EmailConfig {
    public $email = array(
        ...
        // The next line attempts to create a 'Return-path' header
        'returnPath' => '[email protected]',

        // But in some sendmail configurations (esp. on cPanel)
        // you have to pass the -f parameter to sendmail, like this
        'additionalParameters' => '[email protected]',
        ...
    );
}

Or if you need to do it just for a single email, something like this should work...

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('MyConfig');
$email->from(...)
      ->to(...)
      ->subject(...)
      ->returnPath('[email protected]')
      // Haven't tested this next line, but may possibly work?
      ->config(array('additionalParameters' => '[email protected]'))
      ->send();
︶ ̄淡然 2024-08-26 08:17:16

有一个名为 EmailComponent::return 的属性,它是错误消息的返回路径。请注意,这与replyTo 属性不同。

$this->Email->return = '[email protected]';

http://book.cakephp.org/1.3/ en/The-Manual/Core-Components/Email.html

There's an attribute called EmailComponent::return that is the return path for error messages. Note that this is different than the replyTo attribute.

$this->Email->return = '[email protected]';

http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Email.html

被翻牌 2024-08-26 08:17:16

我和一位同事正在研究同样的问题,我们发现编辑 php.ini 中的以下行给了我们修复:

from:

sendmail_path = /usr/sbin/sendmail -t -i

to:

sendmail_path = /usr/sbin/sendmail -t -i -f youremail@address

测试时请确保将您的电子邮件发送到有效的域。这让我们呆了几分钟。

A co-worker and I were working on this same issue, we found that editing the following line in php.ini gave us our fix:

from:

sendmail_path = /usr/sbin/sendmail -t -i

to:

sendmail_path = /usr/sbin/sendmail -t -i -f youremail@address

when testing be sure to send your emails to a valid domain. this caught us for a few minutes.

草莓酥 2024-08-26 08:17:16

要更改 CakePHP 电子邮件组件中的返回路径,我喜欢这样做:

...
$return_path_email = '[email protected]';
...

$this->Email->additionalParams = '-f'.$return_path_email;

它的工作原理就像魅力;)

To change the return path in CakePHP Email component I do like this:

...
$return_path_email = '[email protected]';
...

$this->Email->additionalParams = '-f'.$return_path_email;

and it works like charm ;)

梦巷 2024-08-26 08:17:16

当您查看如何使用组件的其余部分时,深入研究蛋糕手册,您应该会看到类似以下内容的内容。这就是设置返回路径的原因。

$this->Email->return = '[电子邮件受保护] ';

Digging into the cake manual when you were looking at how to use the rest of the component you should have seen something like the following. This is what set the Return-Path.

$this->Email->return = '[email protected]';

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文