我正在使用CakePHP向客戶端發送自動電子郵件。它工作得很好,但似乎有些收件人沒有收到我們的電子郵件。因此,我決定使用SMTP選項發送電子郵件,並通過Media Temple的電子郵件提供商路由電子郵件。 但是,當試圖從Media Temple帳戶發送電子郵件時,出現錯誤「550-不允許繼電器」。 這聽起來像Media Temple服務器只是簡單地不允許我通過它發送郵件。 這很奇怪,因爲我確認了我使用的用戶名和密碼是正確的,我可以通過SMTP通過它從我的macmail客戶端和iPhone郵件客戶端發送郵件。我還確認我的cakephp電子郵件設置是正確的,因爲我可以通過SMTP發送電子郵件,並使用與cakephp完全相同的配置的gmail帳戶。 任何想法,爲什麼我得到這個錯誤,以及如何解決它? 謝謝無法通過SMTP發送電子郵件,因爲「550 - 中繼不允許」
下面是處理髮送電子郵件的代碼。我像使用許多不同控制器中的普通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,//'[email protected]',
'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', '<[email protected]$2>', trim($subEmail));
}
$email=implode(",",$fixedSubEmails);
return $email;
}
}
看看這裏:[解決媒體寺SMTP問題](http://kb.mediatemple.net/questions/74/Troubleshooting+SMTP+problems#gs) – paulsm4 2012-08-15 23:30:36
這聽起來完全像我所需要的,但建議didn'幫助。上的「被拒絕的傳遞」基本上說來驗證我使用的密碼驗證,這裏是我的CakePHP設置: '$這個 - > smtpOptions =陣列( \t「口」 =>「465」, \t「超時」 > '30', \t 'AUTH'=>真, \t '主機'=> 'SSL://mail.thenumber.biz', \t '用戶名'=> '[email protected]', \t'password'=> {密碼}, \t); ' 它也表明它不會工作,如果它是一個新的服務器,但我們已經有多年,併發送電子郵件與桌面客戶端罰款。 – thespacecamel 2012-08-15 23:59:20
你介意發佈做郵件的CakePHP代碼嗎? – Hoff 2012-08-16 14:15:23