我正在Raspberry PI上运行Apache2 Web服务器。每当用户决定填写并提交以下HTML表单时,我都希望向自己发送电子邮件。
<form action="submit_rsvp_form.php" class="rsvp-form ftco-animate">
<div class="">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name">
</div>
<div class="form-group">
<input type="text" name="email" class="form-control" placeholder="Your email">
</div>
</div>
<div class="">
<div class="form-group">
<div class="form-field">
<div class="select-wrap">
<div class="icon d-flex align-items-center justify-content-center"><span class="ion-ios-arrow-down"></span></div>
<select name="guests" id="" class="form-control">
<option value="">Guests</option>
<option value="">0</option>
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">5</option>
</select>
</div>
</div>
</div>
</div>
<div class="">
<div class="form-group">
<textarea name="message" id="" cols="30" rows="2" class="form-control" placeholder="Message"></textarea>
</div>
<div class="form-group">
<input type="submit" value="I am attending" class="btn btn-primary py-3 px-4">
</div>
</div>
</form>
这里是引用的PHP脚本:
<?php
echo isset($_POST['email']);
if(isset($_POST['email'])) {
$email_to = "my_personal_email";
$email_subject = "WEDDING RSVP";
$first_name = $_POST['name'];
$email_from = $_POST['email'];
$location = 'my_town';
$address = 'my_address'; // required
$guests = $_POST['guests'];
$message = $_POST['message'];
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "RSVP answer below.\n\n";
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Location: ".clean_string($location)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "Guests: ".clean_string($guests)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<div class="feedback">Great! We are looking forward to seeing you!</div>
<?php
}
?>
我从StackOverflow获得了PHP脚本,并对其进行了一些更改。
这里的问题是,当我按下按钮时什么也没有显示,甚至没有成功的HTML。
我想知道问题是否出在我的HTML表单的结构中。
我犯了一个明显的错误吗?我不是PHP开发人员,所以我对它的细节一无所知。
感谢您的帮助
我正在Raspberry PI上运行Apache2 Web服务器。每当用户决定填写并提交以下HTML表单时,我都希望向自己发送电子邮件。
我通过将method="POST"
添加到<form>
标签解决了这个问题。