通过SMTP使用phpmailer通过SMTP联络表单,该SMTP在本地主机上工作,但在服务器上不工作

时间:2018-11-02 18:56:55

标签: smtp localhost phpmailer

  • 列表项

        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com'; 
        $mail->Port = 587;
        $mail->SMTPAuth = true; 
        $mail->SMTPSecure = 'tls';                               
        $mail->Username = 'xxxxxxxx@gmail.com';                 
        $mail->Password = 'xxxxxxxxxx';                           
    
        $mail->setFrom($_POST['email'],$_POST['name']);
        $mail->addAddress('xxxxxxxxxx@gmail.com');     
        $mail->addReplyTo($_POST['email'],$_POST['name']);
    
        $mail->isHTML(true);         
        $mail->Subject='Intending to: '.$_POST['option'];                        
        $mail->Body='<h1 align=center> Name :'.$_POST['name'].'<br>Email: '.$_POST['email'].
        '<br>Message: '.$_POST['text'].'</h1>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        if(!$mail->send()) {
            $result="Something went wrong. Please try again.";
        }
        else {
            $result="Thank You ".$_POST['name']." for contacting us. We'll get back to you soon!";
        }
    }
    

    ?> //我得到的错误是致命错误:未捕获的错误:在/storage/ssd4/215/7577215/public_html/index.php:31中找不到类'PHPMailer'堆栈跟踪:#0 {main}丢在/ storage /中ssd4 / 215/7577215 / public_html / index.php,第5行

///仅当文件在服务器上,在localhost上发送邮件时,这种情况才会发生。

1 个答案:

答案 0 :(得分:0)

您还必须上传PHPMailer类,而不仅仅是您的脚本。

您还使用了过时的PHPMailer版本;从GitHub获取最新版本。