2012-10-30 40 views
1

嗨,我們有一個CRM系統需要更改一次由管理員更新SMTP服務器。 我們有一個表,它返回一組數據,其中包含狀態爲1所需的SMTP設置。問題是,它仍然轉發到本地主機的SMTP即使我已經發送SMTP設置到htmlMimeMail.php(類)下面是我的代碼:以編程方式更改SMTP服務器

function sendEmail($txtFrom, $subject, $to, $cc = NULL, $bcc = NULL, $strHTML, $txtModel='') 
    { 
     $sql = "SELECT * FROM smtp_server WHERE status='1'"; 
     $rstemp = $this->cn2->Execute($sql); 
     while(!$rstemp->EOF) 
     { 
      $SMTPid = $rstemp->fields['id']; 
      $SMTPServer = $rstemp->fields['server']; 
      $SMTPPort = $rstemp->fields['port']; 
      $SMTPusername=$rstemp->fields['user']; 
      $SMTPpass=$rstemp->fields['pass']; 
      $SMTPauth = $rstemp->fields['auth']; 
      $rstemp->MoveNext(); 
     } 
     $rstemp->Close(); 


     $fromEmail = $txtFrom; 
     $from  = $fromEmail; 

     $mail = new htmlMimeMail(); 
     $mail->setTextCharset('utf-8'); 
     $mail->setHtmlCharset('utf-8'); 
     $mail->setHeadCharset('utf-8'); 
     $mail->setSMTPParams($SMTPServer, $SMTPPort,$SMTPid,base64_encode($SMTPusername),base64_encode($SMTPpass),$SMTPServer);   
     $mail->setReturnPath($fromEmail); 
     $mail->setFrom($from); 
     $mail->setSubject($subject); 
     $mail->setHTML($strHTML); 

     if(trim($txtModel) != '') 
     { 
      $file = strtoupper($txtModel).".pdf"; 

      if(file_exists($this->dir.$file)) 
      { 
       $attachment = $mail->getFile($this->dir.$file); 
       $mail->addAttachment($attachment, $file, "application/pdf"); 
      } 
     } 

     if (!is_null($cc) && $cc != '') 
     { 
      //$arrEmail = explode(",", $cc); 
      $mail->setCc($cc); 
      //unset($arrEmail); 
     } 

     $mail->setBcc($bcc.', [email protected]'); 

     $arrEmail = explode(",", $to);  
     ini_set("SMTP",$SMTPServer); 
     $result = $mail->send($arrEmail); 

     return $result; 
    } 

我失去了我的代碼的東西嗎? 我還新增了ini_set

這裏是接收參數的函數。

function setSMTPParams($host = null, $port = null, $auth = null, $user = null, $pass = null,$helo = null) 
{ 
    if (!is_null($host)) $this->smtp_params['host'] = $host; 
    if (!is_null($port)) $this->smtp_params['port'] = $port; 
    if (!is_null($helo)) $this->smtp_params['helo'] = $helo; 
    if($auth == 4){ 
     if (!is_null($auth)) $this->smtp_params['auth'] = true; 
    }else{ 
     if (!is_null($auth)) $this->smtp_params['auth'] = false; 
    } 
    if (!is_null($user)) $this->smtp_params['user'] = $user; 
    if (!is_null($pass)) $this->smtp_params['pass'] = $pass; 
} 
 
Table definition 
________________________________________ 
id|server   |port|user|pass|auth |status 
________________________________________ 
1 |localhost  |25 |null|null|false|0 
4 |[email protected]|25 |user|pass|true |1 
________________________________________ 
+0

試過,只是爲了測試,硬編碼的價值,而不是從數據庫中拉他們? – 2012-10-30 09:45:20

+0

也嘗試過硬編碼的值仍然在本地主機上繼續我認爲我缺乏一些東西,但我不知道它是什麼..對此有什麼建議? – Kiel

+0

仍然無法正常工作.. – Kiel

回答

0

從我所看到的,是你送的SMTP數據的類,但你忘了告訴類使用這些數據:

$result = $mail->send($a_to, 'smtp') 

未按規定設置第二個參數在發送類的結果默認爲'郵件'作爲發送類型。

function send($recipients, $type = 'mail') 

,然後使用默認的PHP導致您的系統:

$result = mail($to, $subject, $this->output, implode(CRLF, $headers)); 

case 'mail': 
功能的send()

我不清楚上爲什麼設置使用了htmlMimeMail類啓動時設置的SMTP默認值,可能會進行一些進一步的修改創造這個結果的代碼,我不能說。

我意識到這個問題有點老,目前的htmlMimeMail不會在當前的PHP上沒有錯誤地運行,但是想法不妨給出一個答案。