Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';无法通过SMTP发送电子邮件,因为;550-不允许使用继电器“;_Php_Email_Cakephp_Smtp_Mediatemple - Fatal编程技术网

Php Can';无法通过SMTP发送电子邮件,因为;550-不允许使用继电器“;

Php Can';无法通过SMTP发送电子邮件,因为;550-不允许使用继电器“;,php,email,cakephp,smtp,mediatemple,Php,Email,Cakephp,Smtp,Mediatemple,我正在使用CakePHP向客户发送自动电子邮件。它一直工作得很好,但似乎有些收件人没有收到我们的电子邮件。因此,我决定使用SMTP选项发送电子邮件,并通过我们在Media Temple的电子邮件提供商发送电子邮件。 然而,当尝试从Media Temple帐户发送电子邮件时,我收到错误“550-不允许中继”。 这听起来像是Media Temple服务器不允许我通过它发送邮件。 这很奇怪,因为我已经确认我使用的用户名和密码是正确的,我可以通过SMTP从macmail客户端和iPhone邮件客户端发送

我正在使用CakePHP向客户发送自动电子邮件。它一直工作得很好,但似乎有些收件人没有收到我们的电子邮件。因此,我决定使用SMTP选项发送电子邮件,并通过我们在Media Temple的电子邮件提供商发送电子邮件。 然而,当尝试从Media Temple帐户发送电子邮件时,我收到错误“550-不允许中继”。 这听起来像是Media Temple服务器不允许我通过它发送邮件。 这很奇怪,因为我已经确认我使用的用户名和密码是正确的,我可以通过SMTP从macmail客户端和iPhone邮件客户端发送邮件。我还确认了我的cakephp电子邮件设置是正确的,因为我可以使用与cakephp中配置完全相同的gmail帐户通过SMTP发送电子邮件。 知道我为什么会出现这个错误以及如何解决它吗? 谢谢

下面是处理发送电子邮件的代码。我使用这个类就像使用许多不同控制器中的常规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;
   }
}
类CanadafindsEmailerComponent扩展了EmailComponent
{ 
...
函数send($content=null,$template=null,$layout=null){
if(!in_array(TECHY_MONITOR_EMAIL,$this->bcc)&&is_array($this->bcc))
$this->bcc[]=技术监控电子邮件;
如果(!in_array(TECHY_MONITOR_EMAIL,$this->bcc)&!is_array($this->bcc))
$this->bcc=array(TECHY\u MONITOR\u EMAIL);
if(DEVSITE){//注释掉的代码是使用gmail的smtp的设置,这很好
$this->delivery='smtp';
$this->smtpOptions=array(
'端口'=>'465',//'465',
'超时'=>'30',//'30',
“auth”=>正确,
'主机'=>'ssl://mail.thenumber.biz',//'ssl://smtp.gmail.com',
“用户名”=>用户名,//”USERNAME@gmail.com',
“密码”=>SMTP_密码//,
);
$this->to=$this->correctFormatOn($this->to);
$this->bcc=$this->correctformation($this->bcc);
$this->cc=$this->correctFormatOn($this->cc);
$this->replyTo=$this->correctFormatOn($this->replyTo);
$this->from=$this->correctFormatOn($this->from);
}
返回父项::发送($content、$template、$layout);
}
函数correctFormatOn(&$email){
if(is_数组($email)){
$copiedmail=array();
foreach($singleEmail形式的电子邮件){
$copiedEmail[]=$this->correctformationsingle($singleEmail);
}
$email=$copiedmail;
}否则{
$email=$this->correctformationsingle($email);
}
返回$email;
}
函数更正格式单个(&$email){
$subemail=explode(“,”,$email);
$fixedSubEmails=array();
foreach($subEmail作为$subEmail){

$fixedSubEmails[]=preg_replace('/我遇到的主要问题是客户端没有从我们的服务器接收电子邮件,(因此我想使用SMTP服务器来查看这是否可以修复它,而不是服务器的默认电子邮件服务器)。 但我通过做一些其他更改,设法让这些客户端接收来自服务器的电子邮件,从而消除了使用SMTP和Media Temple电子邮件服务器的需要。 (仅供参考,我发现我们收到了来自客户端电子邮件服务器的反弹,声明
诊断代码:smtp;550访问被拒绝-直升机名称无效(请参阅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,等等,瞧!不再有来自那些特定客户机的反弹,每个人都很高兴。)

我最终编写了自己的PHP邮件()基于的脚本以避免此错误。

看这里:这听起来与我需要的完全一样,但建议没有帮助。“拒绝中继”部分基本上说是为了验证我使用的是密码身份验证,下面是我的cakephp设置:
$this->smtpOptions=array('port'=>'465','timeout'=>'30','auth'=>true',host'=>'ssl://mail.thenumber.biz“,”用户名“=>”michael@thenumber.biz“,”密码“=>{password},)
它还建议,如果是一个新服务器,它将不起作用,但我们已经使用它多年了,并且可以通过桌面客户端发送电子邮件。您介意发布用于发送邮件的CakePHP代码吗?您的PHP代码是否与您测试时的Mac/iPhone从同一域连接?我相信一些中继也需要传入的co连接必须来自受信任的IP范围。@Hoff当然我会发布代码,尽管它非常复杂。