Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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 以编程方式更改SMTP服务器_Php_Email_Smtp - Fatal编程技术网

Php 以编程方式更改SMTP服务器

Php 以编程方式更改SMTP服务器,php,email,smtp,Php,Email,Smtp,您好,我们有一个CRM系统,需要改变SMTP服务器一旦由管理员更新。 我们有一个表,它返回一组数据,其中包含状态为1的SMTP设置。问题是,即使我已将smtp设置发送到htmlimemail.php(类),它仍会中继到本地主机smtp。以下是我的代码: function sendEmail($txtFrom, $subject, $to, $cc = NULL, $bcc = NULL, $strHTML, $txtModel='') { $sql = "SELECT

您好,我们有一个CRM系统,需要改变SMTP服务器一旦由管理员更新。 我们有一个表,它返回一组数据,其中包含状态为1的SMTP设置。问题是,即使我已将smtp设置发送到htmlimemail.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.', sample@email.com');

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

        return $result;
    }
我的代码中遗漏了什么吗? 我还添加了ini_集

下面是接收参数的函数

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 |服务器|端口|用户|通过|身份验证|状态 ________________________________________ 1 | localhost | 25 | null | null | false | 0 4 |somesmtp@mail.com|25 |用户|通过|正确| 1 ________________________________________
据我所见,您已将SMTP数据发送给该类,但忽略了告诉该类使用该数据:

$result = $mail->send( $a_to, 'smtp' )
未能在send中设置第二个参数导致类默认为“mail”作为发送类型

function send($recipients, $type = 'mail')
这将导致系统使用默认的PHP:

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

case 'mail':
函数send()的名称

我不清楚为什么安装程序会使用启动HTMLIMEMAIL类时设置的SMTP默认值,我不能说可能会对创建该结果的代码进行进一步修改


我意识到这个问题有点老了,当前的HTMLIMEMail在当前的PHP上运行时也不会没有错误,但我想还是给出一个答案吧。

尝试过,只是为了测试,硬编码的价值观,而不是拉他们从数据库?尝试也硬编码的价值观仍然继电器在本地主机上我认为我缺乏一些东西,但我不知道它是。。有什么建议吗?
case 'mail':