如何让 Phpmailer 邮件发送具有到另一个域的返回路径的消息
我正在使用第 3 方 SMTP 服务来发送新闻通讯。因此,我的 ISP 不接受退回邮件,因为它们来自并非由他们发送的电子邮件。好的。因此,我使用 SMTP 服务设置了一个邮箱来接受退回邮件。
但是,我的邮件列表程序拒绝发送返回路径与发件人字段具有不同域的电子邮件。
我相信这是由 phpmailer 在其邮件发送例程中引起的:
关键代码似乎是这样,但我不是 PHP 专家,无法弄清楚如何绕过它正在执行的任何检查,我认为这有一些与安全模式有关。我想要使用的返回路径值在变量中: $this->Sender
/**
* Sends mail using the PHP mail() function.
* @param string $header The message headers
* @param string $body The message body
* @access protected
* @return bool
*/
protected function MailSend($header, $body) {
$toArr = array();
foreach($this->to as $t) {
$toArr[] = $this->AddrFormat($t);
}
$to = implode(', ', $toArr);
$params = sprintf("-oi -f %s", $this->Sender);
if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->Sender);
if ($this->SingleTo === true && count($toArr) > 1) {
foreach ($toArr as $key => $val) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$ body);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$b ody);
}
} else {
if ($this->SingleTo === true && count($toArr) > 1) {
foreach ($toArr as $key => $val) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$ body);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$b ody);
}
}
if (isset($old_from)) {
ini_set('sendmail_from', $old_from);
}
if(!$rt) {
throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
}
return true;
}
有谁知道这段代码中的内容阻止我为我的返回路径使用不同的域,或者更好的是,有谁知道如何我可以修复(或破解)这个问题,这样它就会发送我的邮件吗?
I'm using a 3rd party SMTP service for sending my newsletters. Because of that, my ISP does not accept bounces because they are coming from an email not originating with them. Okay. So I set up a mailbox with my SMTP service to accept the bounces.
However, my mailing list program is refusing to send out emails whose return-path has a different domain than the from field.
I believe this is caused by phpmailer in it's mailsend routine:
The key code appears to be this, but I'm not that much of an expert with PHP to figure out how to get around whatever check it is doing, which I think has something to do with that safe_mode. The return-path value that I want to use is in the variable: $this->Sender
/**
* Sends mail using the PHP mail() function.
* @param string $header The message headers
* @param string $body The message body
* @access protected
* @return bool
*/
protected function MailSend($header, $body) {
$toArr = array();
foreach($this->to as $t) {
$toArr[] = $this->AddrFormat($t);
}
$to = implode(', ', $toArr);
$params = sprintf("-oi -f %s", $this->Sender);
if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->Sender);
if ($this->SingleTo === true && count($toArr) > 1) {
foreach ($toArr as $key => $val) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$ body);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$b ody);
}
} else {
if ($this->SingleTo === true && count($toArr) > 1) {
foreach ($toArr as $key => $val) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$ body);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$b ody);
}
}
if (isset($old_from)) {
ini_set('sendmail_from', $old_from);
}
if(!$rt) {
throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
}
return true;
}
Does anyone know what in this code is preventing me from using a different domain for my return-path, or better yet, does anyone know how I can fix (or hack) this so it will send out my mail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Sanmai 的评论让我查看了参数。当我开始在 phpmailer 例程中测试其中一些代码时,我发现代码没有执行。所以至少他帮助我意识到问题出在其他地方。
我仍然有问题。我现在将尝试更好地隔离它。那么也许我可以解决它,如果不能,我会修改这个问题并再试一次。
谢谢你给了我一些继续下去的机会。
@Sanmai's comment got me looking at the parameters. When I started testing some of them in the phpmailer routine, I found the code wasn't executed. So at least he helped me realize the problem's somewhere else.
I still have the problem. I'll now try to better isolate it. Then maybe I can solve it, and if not, I'll modify this question and try again.
Thanks for giving me a bit of something to go on.
你遇到什么错误?您使用的邮件服务器可能不允许不同的返回地址域,以防止其服务被用来发送垃圾邮件。
What error are you getting? It could be that the mailer server you are using doesn't allow different return address domains to prevent their service being used to send spam.