电子邮件在本地主机上发送,但不在Live服务器上发送

时间:2016-02-04 08:07:09

标签: php html-email

我在我的网站上有一个表单,并且在本地主机上发送电子邮件但是在实时服务器上邮件没有通过,我收到一条错误消息:“内部服务器错误”。我想知道它是否是主机代码的问题。请提前帮助解决这个问题

以下是代码

<?php

$webmaster_email = "yawsamuel@ghanaeuropeanyouthcongress.com";

$feedback_page = "feedback.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";

$name = $_REQUEST['name'] ;
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;


function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str)) {
        return true;
    }
    else {
        return false;
    }
}

if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}

elseif (empty($name) || empty($email_address) || empty($comments)) {
header( "Location: $error_page" );
}


elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}

else {
$to = $webmaster_email; 
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email_address \n Message: \n $comments"; 

    $headers = "From: $webmaster_email\n"; 
    $headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers)
header( "Location: $thankyou_page" );`
}
?>

1 个答案:

答案 0 :(得分:0)

您有语法错误,从而导致500内部服务器错误:

mail($to,$email_subject,$email_body,$headers); // missed out a semi-colon
header( "Location: $thankyou_page" ); // extra backpack

提示:您应该通过将此代码添加到PHP文件的顶部来启用Error Reporting,这将有助于您查找错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);