doudi8298 2013-04-28 18:41
浏览 48
已采纳

PHPMailer不从smtp主机发送

I'm using PHPMailer and I set it up to use SMTP for sending emails. The problem is, it's not connecting to the SMTP server but instead its trying to send mail from the hosting server. Heres the code i created:

                $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();
  • 写回答

1条回答 默认 最新

  • doujiang1939 2013-04-28 19:06
    关注

    I fixed it by commenting out $mail->IsSMTP()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?