Php 为什么我的表单邮件脚本不起作用?

Php 为什么我的表单邮件脚本不起作用?,php,forms,email,Php,Forms,Email,我在互联网上搜索了一个脚本,可以让你在电子邮件中发送表单。但当我按下提交按钮时,我会进入感谢页面。所以它应该已经被发送了。但事实并非如此。 有人能帮我吗 发送脚本: <?php /* This first bit sets the email address that you want the form to be submitted to. You will need to change this value to a valid email address that you can a

我在互联网上搜索了一个脚本,可以让你在电子邮件中发送表单。但当我按下提交按钮时,我会进入感谢页面。所以它应该已经被发送了。但事实并非如此。 有人能帮我吗

发送脚本:

<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "dj-sam@live.nl";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "feedback_form.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$naam = $_REQUEST['naam'] ;
$wedstrijd1 = $_REQUEST['wedstrijd1'] ;
$wedstrijd2 = $_REQUEST['wedstrijd2'] ;
$wedstrijd3 = $_REQUEST['wedstrijd3'] ;
$wedstrijd4 = $_REQUEST['wedstrijd4'] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
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 the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['naam'])) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($naam) || empty($wedstrijd1) || empty($wedstrijd2) || empty($wedstrijd3) || empty($wedstrijd4) ) {
header( "Location: $error_page" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($naam) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email", "Nieuwe voorspelling ingestuurd!",
$naam,
$wedstrijd1,
$wedstrijd2,
$wedstrijd3,
$wedstrijd4);
header( "Location: $thankyou_page" );
}
?>

您误用了mail命令。如果查看,您可以看到您现在正在覆盖附加的头。如果您没有在附加头中向它提供发件人地址,它将无法发送。在没有附加参数的情况下,它使用php配置文件中的任何内容作为默认值

您要传递的参数似乎是作为电子邮件消息体的一部分,但是mail命令仅使用单个字符串作为消息体。在调用mail之前,必须连接字符串输入,并将整个主题作为单个参数传递

<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "dj-sam@live.nl";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "feedback_form.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$naam = $_REQUEST['naam'] ;
$wedstrijd1 = $_REQUEST['wedstrijd1'] ;
$wedstrijd2 = $_REQUEST['wedstrijd2'] ;
$wedstrijd3 = $_REQUEST['wedstrijd3'] ;
$wedstrijd4 = $_REQUEST['wedstrijd4'] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
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 the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['naam'])) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($naam) || empty($wedstrijd1) || empty($wedstrijd2) || empty($wedstrijd3) || empty($wedstrijd4) ) {
header( "Location: $error_page" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($naam) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
    $message = $naan . $wedstrijd1 . $wedstrijd2 . $wedstrijd3 . $wedstrijd4;
    if( mail( "$webmaster_email", "Nieuwe voorspelling ingestuurd!", $message))
    {
        header( "Location: $thankyou_page" );
    }
    else
    {
        header( "Location: $error_page" );
    }
}
?>

PHP邮件方法是在as上定义的

邮件(字符串$to,字符串$subject,字符串$message[,字符串$additional_Header[,字符串$additional_parameters]])

哪些映射到您的代码为

$to=$webmaster\u电子邮件

$subject=Nieuwe voorspelling摄取量

$message=$naam

$additional_headers=$wedstrijd1

$additional_参数=$wedstrijd2

我猜你希望$wedstrijd1等成为信息的一部分

因此,在我看来,从from返回信息的最佳方法是将所有变量放在一个格式化的消息中以便发送

$message = "Name = {$naam}\n"
    ."Competition 1 = {$wedstrijd1}\n"
    ."Competition 2 = {$wedstrijd2}\n"
    ."Competition 3 = {$wedstrijd3}\n"
    ."Competition 4 = {$wedstrijd4}\n";

mail( $webmaster_email, "Nieuwe voorspelling ingestuurd!", $message);

附加的_头通常用于设置发件人、抄送和密件抄送等

,但当我删除所有“wedstrijd”1、2、3和4时,电子邮件将发送。我所说的代码://如果我们通过了之前的所有测试,请发送电子邮件,然后重定向到感谢页面。else{mail($webmaster_email)、$Nieuwe voorspelling insteuurd!”、$naam、$wedstrijd1、$wedstrijd2、$wedstrijd3、$wedstrijd4);header($Location:$thankyou_page”);@change1001您是使用开发服务器从家中发送的吗?@AJHenderson那么我该如何解决这个问题呢?(回复您的编辑)@change1001-这取决于您为这些参数传递的内容。如果您确实需要这些额外的头,您需要确保从数据中传递。如果你只是在做基本的邮件,那么你就不需要它们了。@AJHenderson我真的不明白你在说什么。我真的是新的编码。。。