2016-05-06 52 views
0

我在本地主機上有一個非常簡單的HTML CSS和javaScript網站。我想做一個非常簡單的聯繫表單。通常我通過插件使用WordPress來實現這一點,並且從未在普通網站上手動創建電子郵件。phpMailer - localhost當前無法處理此請求。

我已經從:https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php下載了class.phpmailper.php文件,並將其放入我的網站的根目錄。

在我接觸的形式我做一個簡單的

if(isset($_POST['submit'])){ 

} 

,並嘗試發送電子郵件。我已經把我用在我的WordPress網站,相同的SMTP細節但是當我點擊提交頁面只是說:

網站名稱頁面無法正常工作

envirofuel,重新設計目前無法處理此請求。

HTTP 500錯誤

這是當表單提交時執行的代碼:

if(isset($_POST['submit'])){ 

    require_once('class.phpmailer.php'); 

    $subject = 'test'; 
    $body_of_your_email = 'hello test body'; 
    $mail = new PHPMailer(); 

    $mail->IsSMTP();      // telling the class to use SMTP 

    $mail->SMTPDebug = 0; 
    // 0 = no output, 1 = errors and messages, 2 = messages only. 

    $mail->SMTPAuth = true;    // enable SMTP authentication 
    $mail->SMTPSecure = "";    // sets the prefix to the servier 
    $mail->Host = "I PUT MY SMTP HOST HERE";  // sets Gmail as the SMTP server 
    $mail->Port = 587;      // set the SMTP port for the GMAIL 

    $mail->Username = "I PUT MY USERNAME HERE"; // Gmail username 
    $mail->Password = "I PUT MY PASSWORD HERE";  // Gmail password 

    $mail->CharSet = 'windows-1250'; 
    $mail->SetFrom ('[email protected]', 'Example.com Information'); 
    $mail->AddBCC ('[email protected]', 'Example.com Sales Dep.'); 
    $mail->Subject = $subject; 
    $mail->ContentType = 'text/plain'; 
    $mail->IsHTML(false); 

    $mail->Body = $body_of_your_email; 
    // you may also use $mail->Body = file_get_contents('your_mail_template.html'); 

    $mail->AddAddress ('I PUT MY PERSONAL EMAIL HERE', 'Matthew'); 
    // you may also use this format $mail->AddAddress ($recipient); 

    if(!$mail->Send()) 
    { 
     $error_message = "Mailer Error: " . $mail->ErrorInfo; 
    } else 
    { 
     $error_message = "Successfully sent!"; 
    } 

} 

任何想法?

+1

錯誤500是服務器級錯誤。日誌說什麼?你有沒有運行調試工具? – Webomatik

+0

你已經將你的代碼基於一個過時的PHPMailer示例。更新它。您收到的錯誤(將在您的Web服務器日誌中)可能是您尚未加載SMTP類。 – Synchro

回答

0

如果您的Wordpress網站能夠發送電子郵件,您的電子郵件服務器設置應該是好的。

您可能需要配置PHP來使用SMTP,嘗試所有前加入:

ini_set('SMTP','localhost'); 
ini_set('sendmail_from', '[email protected]_domain.com'); 

如果一切正常,那麼你可以修改你的php.ini以使這些設置全局。

[mail function] 
SMTP = localhost 
sendmail_from = [email protected]_domain.com 
相關問題