嗨,我们有一个 CRM 系统,一旦管理员更新,就需要更改 SMTP 服务器。我们有一个表,它返回一组数据,其中包含状态为 1 的 SMTP 设置。问题是即使我已将 SMTP 设置发送到 htmlMimeMail.php(类),它仍然会中继到 localhost 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.', sample@email.com');
$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;
}
表定义 ________________________________________ id|server |port|user|pass|auth |status ________________________________________ 1 |本地主机 |25 |null|null|false|0 4 |somesmtp@mail.com|25 |user|pass|true |1 ________________________________________