0

希望只是一个快速的问题,我已经设置了一个这样的表格 - 电子邮件,姓名和消息。如何在发送时检查它是否有这三样东西,如果有,然后发送到所需的电子邮件?

我已经尝试查看 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"; } } 
?>
4

2 回答 2

1
if(!empty($_POST['email']) && !empty($_POST['name']) && !empty($_POST['message'])){
//send email code
}else{
//dont
}
于 2013-05-30T09:30:23.743 回答
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>
于 2013-05-30T09:56:08.850 回答