0

在我的页面中,我的表单包含多个 textarea,我需要一种方法来在一封电子邮件中收集所有 textarea,然后发送。

我需要一种方法,我可以将它添加到每个页面并自动执行此操作,而不是按名称引用每个文本区域。

$email_body = "You have received a new message from the user $name. \r\n".
    "Here is the answer to the $step. \r\n $message \r\n Comments:$comments.\r\n".

而不是$message我想要所有的文本区域。

4

1 回答 1

2

让我们重新写下整个答案。

HTML 表单:[index.html]:

<html>
<body>
<form action="php_file.php" method="post">
<input type="text" name="field_1"/>
<input type="text" name="something_else"/>
<input type="text" name="third_field"/>
<input type="submit" name="submit" value="send!"/>
</form>
</body>
</html>

PHP 文件(处理器):[php_file.php:]

    $email_body = '';
    foreach($_POST as $key => $value)
    {
        $email_body .= "Field name: ".$key . "Value: ".$value."<br />";
    }

//send email with $email_body as the email body!
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "website@stacksomething.com";
$headers = "From:" . $from;
mail($to,$subject,$email_body ,$headers);
echo "Email was sent!";
于 2013-01-26T16:10:01.293 回答