希望只是一个简单的问题,我有一个像这样的表单 - 电子邮件,名称&信息。如何在发送时检查它是否有这3件事,如果有,那么它会发送到所需的电子邮件?
我已经尝试过查看php文档,但我对它没有多大意义。我今天有点厚。 谢谢你:)
<form action="" method="post">
<!--[if IE]> <br> <label for="email">Email</label> <br> <end if -->
<input type="email" name="email" id="email" placeholder="Email*" required>
<br>
<!--[if IE]> <br> <label for="name">Name</label> <br> <end if -->
<input type="text" name="name" id="name" placeholder="Name*" required>
<br>
<!--[if IE]> <br> <label for="message">Message</label> <br> <end if -->
<textarea name="message" id="message" placeholder="Description*" required></textarea>
<input type="submit" value="Send">
</form>
我在这里收到了电子邮件的PHP代码 - 这里出了什么问题? (也许我可以编辑它来工作?)抱怨大约2个参数,而不是3。
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST') {
if (mail('Someemail@tnelectricalsussex.co.uk',
"Name: " . $_POST['name'] . PHP_EOL .
"Email: " . $_POST['email'] . PHP_EOL .
"Message: " . $_POST['message']) ) {
$status = "Sent"; } }
?>
答案 0 :(得分:1)
if(!empty($_POST['email']) && !empty($_POST['name']) && !empty($_POST['message'])){
//send email code
}else{
//dont
}
答案 1 :(得分:1)
我完全忘记添加主题行(感谢@Dagon) - 这是正确运行的代码
PHP
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST') {
if (mail('someone@somewhere.co.uk',
'Enquiries',
"Name: " . $_POST['name'] . PHP_EOL .
"Email: " . $_POST['email'] . PHP_EOL .
"Message: " . $_POST['message']) ) {
$status = "Sent"; } }
?>
HTML
<form action="" method="post">
<!--[if IE]> <br> <label for="email">Email</label> <br> <end if -->
<input type="email" name="email" id="email" placeholder="Email*" required>
<br />
<!--[if IE]> <br> <label for="name">Name</label> <br> <end if -->
<input type="text" name="name" id="name" placeholder="Name*" required>
<br />
<!--[if IE]> <br> <label for="message">Message</label> <br> <end if -->
<textarea name="message" id="message" placeholder="Description*" required></textarea>
<input type="submit" value="Send">
</form>