2

我有一个位于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"];
4

2 回答 2

2

请检查 PHPmail函数的正确形式:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

参考: http: //php.net/manual/en/function.mail.php


消息应该是第三个参数,不是吗?

你写的是:

mail( "$webmaster_email, designedondemandcorp@gmail.com", "Feedback",
  $EmailAddress, $IssueType, $Comments );

像这样重写它:

$messageBody = "Comments : ".$Comments." Issue : ".$IssueType;
mail("$webmaster_email, designedondemandcorp@gmail.com", "Feedback", $messageBody);

只是想让它看看是否有问题$_POST,但我想我上面的代码将解决这个问题(只需将所有数据捆绑在一个$messageBodyvar 中并将其传递给mail函数)。

于 2013-02-13T07:54:53.400 回答
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" );
}
于 2013-02-13T07:57:41.333 回答