我编辑了一个从互联网上下载的简单联系表格,我不是一个大家伙,所以我很可能做错了。
这是我的代码:
<?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 = "xxxxxxxx@me.com"; /* ENTER EMAIL ADDRESS TO THE LEFT INSIDE THE QUOTES */
/*
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 = "index.html";
$error_page = "index.html";
$thankyou_page = "index.html";
/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$phone = $_REQUEST['phone'] ;
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['message'] ;
/*
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['email_address'])) {
header( "Location: $feedback_page" );
}
// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($comments)) {
header( "Location: $error_page" );
}
// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}
// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email", "CDR-Print Enquiry",
"Name: $name", "Company: $company", "Phone: $phone", "From: $email_address", "Message: $comments" );
header( "Location: $thankyou_page" );
}
?>
答案 0 :(得分:3)
邮件功能最多可以包含5个参数,在你的情况下它占用7个,而且大多数都没有意义:
mail( "$webmaster_email", "CDR-Print Enquiry", "Name: $name", "Company: $company", "Phone: $phone", "From: $email_address", "Message: $comments");
请检查mail manual以了解您的脚本应该如何工作,基本上您需要这样做:
mail('person@example.com', 'My Subject', $message);
答案 1 :(得分:0)
错误发生在您的邮件功能
中它应该是这样的:
$message = 'Name: $name, Company: $company Phone: $phone From: $email_address Message: $comments'
mail( "$webmaster_email", "CDR-Print Enquiry", $message);
请检查this链接,以便您更好地了解邮件功能。
答案 2 :(得分:0)
是否有错误?或者只是不发送邮件?您可以通过运行mail
来检查if
函数是否成功,因为mail
返回了它成功的布尔值。