Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 电子邮件在本地主机上发送,但不在实时服务器上发送_Php_Html Email - Fatal编程技术网

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

Php 电子邮件在本地主机上发送,但不在实时服务器上发送,php,html-email,Php,Html Email,我在我的网站上有一个表单,在本地主机上发送电子邮件,但在实时服务器上邮件无法通过,我收到一条错误消息:“内部服务器错误”。我想知道这是否是主机代码的问题。请帮助解决这个问题,提前谢谢 下面是代码 <?php $webmaster_email = "yawsamuel@ghanaeuropeanyouthcongress.com"; $feedback_page = "feedback.html"; $error_page = "error_message.html"; $thankyo

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

下面是代码

<?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" );`
}
?>

您有语法错误,因此导致500个内部服务器错误:

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

提示:您应该将此代码添加到PHP文件的顶部,以帮助您查找错误

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

这一定是防火墙问题。您的本地设置如何?您的live server的配置是否与您检查错误日志所需的方式完全相同(我相信您必须将其配置为允许发送电子邮件)。很可能您没有配置本地邮件服务器。同样在发帖前搜索,这个问题有很多重复。可能重复我只是想知道如何使用php函数“mail()”在本地主机上发送电子邮件。尝试使用SMTP,以便它可以在本地主机和实时服务器上工作。