我的表格位于https://pnrbuilder.com/_popups/feedback_popup.html
表单使用post将输入传递给php页面,该页面发送包含帖子内容的电子邮件,然后重定向用户。
输入字段工作正常,但textarea内容不适用于电子邮件。
知道我做错了吗?
PHP页面:
<?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 = "support@email.com";
/*
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.
*/
$EmailAddress = $_POST['EmailAddress'] ;
$IssueType = $_POST['IssueType'] ;
$Comments = $_POST['Comments'] ;
/*
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 email injection is detected, redirect to the error page.
if ( isInjected($EmailAddress) ) {
header( "Location: $error_page" );
}
// If we passed the previous test, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email, test@email.com", "Feedback",
$EmailAddress, $IssueType, $Comments );
header( "Location: $thankyou_page" );
}
?>
如果我将下面的内容放在我的php页面的顶部,它就会回显textarea的内容
echo $_POST["EmailAddress"];
echo $_POST["IssueType"];
echo $_POST["Comments"];
答案 0 :(得分:2)
请查看PHP mail
函数的正确形式:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
参考: http://php.net/manual/en/function.mail.php
消息应该是第三个参数,nope?
你写的是:
mail( "$webmaster_email, designedondemandcorp@gmail.com", "Feedback",
$EmailAddress, $IssueType, $Comments );
像这样改写:
$messageBody = "Comments : ".$Comments." Issue : ".$IssueType;
mail("$webmaster_email, designedondemandcorp@gmail.com", "Feedback", $messageBody);
只是想让它看看$_POST
是否有问题,但我想我上面的代码会解决问题(只需将所有数据捆绑在$messageBody
var中并传递给它到mail
函数。)
答案 1 :(得分:1)
发送电子邮件
您将错误的参数传递给mail()
:
mail( "$webmaster_email, designedondemandcorp@gmail.com", "Feedback", $EmailAddress, $IssueType, $Comments);
应该是:
$contents = <<<EOM
Email: $emailAddress
Issue type: $IssueType
Comments:
$Comments
EOM;
mail( "$webmaster_email, designedondemandcorp@gmail.com", "Feedback", $contents);
电子邮件验证
其次,您应该使用正确的电子邮件验证:
$emailAddress = filter_input(INPUT_POST, 'EmailAddress', FILTER_VALIDATE_EMAIL);
if ($emailAddress === false) {
header( "Location: $error_page" );
}