在我的页面中,我的表单有几个textarea,我需要一种方法来收集一封电子邮件中的所有textareas,然后发送它。
我需要一种方法,我可以将其添加到每个页面并自动执行此操作,而不是按名称引用每个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
我想要所有textareas。
答案 0 :(得分: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!";