SMTP Error: Could not connect to SMTP host.
我用网页运行时正常,能发送,用命令运行php文件时报错,主要代码经检查无误,如下
function sendmail($setEmail, $setName, $body, $subject) {<br /> require_once("PHPMail/phpmailer.php");<br /> $mail = new PHPMailer ( true ); // the true param means it will throw exceptions on errors, which we need to catch<br /> $mail->IsSMTP (); // telling the class to use SMTP<br /> try {<br /> $mail->SMTPAuth = true; // enable SMTP authentication<br /> $mail->SMTPSecure = SBT_SSL; // sets the prefix to the servier<br /> $mail->Host = SBT_SMTP_HOST; // sets GMAIL as the SMTP server<br /> $mail->Port = SBT_SMTP_PORT; // set the SMTP port for the GMAIL server<br /> $mail->Username = SBT_SMTP_USER; // GMAIL username<br /> $mail->Password = SBT_SMTP_PASS; // GMAIL password<br /> $mail->AddReplyTo ( SBT_MAIL_FROM, SBT_MAIL_FROM_NAME );<br /> $mail->AddAddress ( $setEmail, $setName );<br /> $mail->SetFrom (SBT_SMTP_USER,SBT_SMTP_USER); //sender name<br /> $mail->Subject = $subject; <br /> $mail->MsgHTML ( $body ); <br /> if (! $mail->Send ()) {//(这边没报错)<br /> echo "Message could not be sent. <p>";<br /> echo "Mailer Error: " . $mail->ErrorInfo;<br /> exit ();<br /> } <br /> } catch ( phpmailerException $e ) {<br /> echo $e->errorMessage (); //Pretty error messages from PHPMailer(就是这边输出错误的)<br /> } catch ( Exception $e ) {<br /> echo $e->getMessage (); //Boring error messages from anything else!<br /> }<br /> }