PHPMailer未从smtp主机发送

PHPMailer未从smtp主机发送,php,smtp,phpmailer,Php,Smtp,Phpmailer,我正在使用PHPMailer并将其设置为使用SMTP发送电子邮件。问题是,它没有连接到SMTP服务器,而是试图从托管服务器发送邮件。以下是我创建的代码: $mail = new PHPMailer ( true ); $mail->IsSMTP (); $mail->Host = $res ['outgoingmailserverhost']; if(in_

我正在使用
PHPMailer
并将其设置为使用
SMTP
发送电子邮件。问题是,它没有连接到SMTP服务器,而是试图从托管服务器发送邮件。以下是我创建的代码:

                $mail = new PHPMailer ( true );
                $mail->IsSMTP ();
                $mail->Host = $res ['outgoingmailserverhost'];
                if(in_array($res['outgoingmailserverencryptedconnectiontype'],array('ssl','tls'))){
                    $mail->SMTPSecure = $res ['outgoingmailserverencryptedconnectiontype'];
                }
                $mail->SMTPDebug = 2;
                $mail->SMTPAuth = true;
                $mail->Port = ( int ) $res ['outgoingmailserverport'];
                $mail->Username = $imapUser;
                $mail->Password = $imapPass;
                $mail->SetFrom($fromaddress,$fromname);
                $mail->AddReplyTo($fromaddress,$fromname);
                foreach($allrecipients as $type=>$recip){
                    foreach($recip as $recs){
                        if($type==='cc'){
                            $mail->AddCC($recs);
                        } elseif($type==='bcc'){
                            $mail->AddBCC($recs);
                        } elseif($type==='to'){
                            $mail->AddAddress($recs);
                        }
                    }
                }
                $mail->Subject = $subject;
                $mail->AltBody = $textbody;
                $mail->MsgHTML($htmlbody);
                if($attachment1!==null){
                    $attachment1= BASE_PATH . '/data/uploads/' . $attachment1;
                    $mail->AddAttachment($attachment1);
                }
                if($attachment2!==null){
                    $attachment2= BASE_PATH . '/data/uploads/' . $attachment2;
                    $mail->AddAttachment($attachment2);
                }
                if($attachment3!==null){
                    $attachment3= BASE_PATH . '/data/uploads/' . $attachment3;
                    $mail->AddAttachment($attachment3);
                }
                $mail->Send();

我通过注释掉
$mail->IsSMTP()