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 ________________________________________
試過,只是爲了測試,硬編碼的價值,而不是從數據庫中拉他們? – 2012-10-30 09:45:20
也嘗試過硬編碼的值仍然在本地主機上繼續我認爲我缺乏一些東西,但我不知道它是什麼..對此有什麼建議? – Kiel
仍然無法正常工作.. – Kiel