我正在使用CakePHP向客户发送自动电子邮件。它工作得很好,但似乎有些收件人没有收到我们的电子邮件。因此,我决定使用SMTP选项发送电子邮件,并通过我们在Media Temple的电子邮件提供商路由电子邮件。但是,当尝试从Media Temple帐户发送电子邮件时,我收到错误消息"550-不允许中继“。这听起来像是Media Temple服务器不允许我通过它发送邮件。这很奇怪,因为我已经确认我使用的用户名和密码是正确的,并且我可以通过它从我的macmail客户端和iPhone邮件客户端通过SMTP发送邮件。我还确认了我的cakephp电子邮件设置是正确的,因为我可以通过SMTP发送电子邮件,gmail帐户与cakephp中的配置完全相同。你知道为什么我会得到这个错误,以及如何解决它吗?谢谢
下面是处理发送电子邮件的代码。我在许多不同的控制器中使用这个类,就像使用常规的EmailComponent一样。
class CanadafindsEmailerComponent extends EmailComponent
{
...
function send($content = null, $template = null, $layout = null) {
if(!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && is_array($this->bcc))
$this->bcc[]=TECHY_MONITOR_EMAIL;
else if (!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && !is_array($this->bcc))
$this->bcc=array(TECHY_MONITOR_EMAIL);
if(DEVSITE){//commented-out code are settings for smtp with gmail, which works fine
$this->delivery = 'smtp';
$this->smtpOptions = array(
'port'=>'465',//'465',
'timeout'=>'30',//'30',
'auth' => true,
'host' => 'ssl://mail.thenumber.biz',//'ssl://smtp.gmail.com',
'username'=>USERNAME,//'USERNAME@gmail.com',
'password'=>SMTP_PASSWORD//,
);
$this->to=$this->correctFormatOn($this->to);
$this->bcc=$this->correctFormatOn($this->bcc);
$this->cc=$this->correctFormatOn($this->cc);
$this->replyTo=$this->correctFormatOn($this->replyTo);
$this->from=$this->correctFormatOn($this->from);
}
return parent::send($content,$template,$layout);
}
function correctFormatOn(&$email){
if(is_array($email)){
$copiedEmail=array();
foreach($email as $singleEmail){
$copiedEmail[]=$this->correctFormatOnSingle($singleEmail);
}
$email=$copiedEmail;
}else{
$email=$this->correctFormatOnSingle($email);
}
return $email;
}
function correctFormatOnSingle(&$email){
$subEmails=explode(",",$email);
$fixedSubEmails=array();
foreach($subEmails as $subEmail){
$fixedSubEmails[]=preg_replace('/,]+)[>,]?/i', '<$1@$2>', trim($subEmail));
}
$email=implode(",",$fixedSubEmails);
return $email;
}
}
发布于 2012-08-17 07:03:12
我遇到的主要问题是客户端无法从我们的服务器接收电子邮件(所以我想使用SMTP服务器,而不是服务器的默认电子邮件服务器)。但我设法让这些客户端通过一些其他更改从服务器接收电子邮件,从而消除了使用SMTP和Media Temple电子邮件服务器的需要。(作为参考,我发现我们收到了来自客户端电子邮件服务器的回复,声明Diagnostic-Code: smtp; 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1),但它们被直接发送回服务器,并进入linux用户帐户"www-data“。(我在/var/mail/www-data中读取它们,只使用tail和vim)。我发现处理电子邮件发送的postfix将电子邮件发送者的主机名(即"HELO name")标记为canadafinds3,这是我在Rackspace中为服务器指定的名称,而不是域名: canadafinds.com。所以我在/etc/postfix/main.cf中进行了更改,重新启动了postfix,等等!不再有来自这些特定客户的反弹,每个人都再次高兴起来。)
发布于 2012-08-17 07:05:20
我最终编写了自己的PHP mail()脚本,基于
http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/
为了避免这个错误。
https://stackoverflow.com/questions/11978721
复制相似问题