2016-05-06 176 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 
相关问题