我已经设置了一个表单并为它编写了php,当我按下提交时,我收到了一封预期的电子邮件,除了它不知道名字字段中的任何内容,我无法弄清楚原因。
HTML:
<form action="#" method="post" class="feedback_ajax_form">
<input type="text" class="input" name="yourname" id="name_f" value="Name*" class="required" onfocus="if (this.value == 'Name*') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Name*';}">
<input type="text" class="input" name="email" id="email_f" value="Email*" class="required" onfocus="if (this.value == 'Email*') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Email*';}">
<textarea name="message" id="message_f" class="required"></textarea>
<input type="submit" value="SUBMIT" id="send_f">
</form>
PHP:
$to = "test@exampleemail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message.";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "New Message recievedt:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$send = mail($to, $subject, $body, $headers);
?>
这是我通常会在电子邮件中收到的内容:
name:
email: example@example.com
phone: 01234 987654
message: Lorem Ipsum
如果有人可以提供帮助,我们将不胜感激。
答案 0 :(得分:3)
$_REQUEST['name']
应为$_REQUEST['yourname']
。
答案 1 :(得分:2)
$to = "test@exampleemail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['yourname'];
$headers = "From: $from";
$subject = "You have a message.";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "New Message recievedt:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$send = mail($to, $subject, $body, $headers);