点击提交按钮

时间:2018-01-06 18:53:31

标签: php html forms

有一些PHP问题。

我已经使用PHP的mail()函数编写了一些代码 - 我已经测试了它并且它正确发送。 (通过不使用if语句测试它,它只是在刷新时运行)。

然后我创建了一个带有提交按钮的表单(电子邮件,电话,消息等)。

将PHP电子邮件功能放在if语句中(我已尝试以下if语句来检查表单是否已提交: 如果(isset($ _ POST)){ 如果($ _ POST) if($ _ SERVER [' REQUEST_METHOD'] ==" POST") 错误,以及我在这里找到的其他一些人,但他们基本上都检查是否有任何事情已通过邮寄提交。

以下是代码:

if($_SERVER['REQUEST_METHOD'] == "POST")  
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];


//BEGIN EMAIL FUNCTION

//headers
$additional_headers[] = 'From: no-reply@<my website went here>';
$additional_headers[] = 'Content-type: text/html; charset=iso-8859-1';
$additional_headers[] = 'MIME-Version: 1.0';
//end headers


$to = '<my email here>';
$subject = "[Contact Form Message] " . $name;
$bodymessage = '
<html>
    >LENGTHY HTML HERE, no need to see that. Completely irrelevant to everything else<
</html>

';


mail($to, $subject, $bodymessage, implode("\r\n", $additional_headers).  $additional_parameters);
$feedback = 'Message Sent.';}

然后我在这里有HTML:

<div class="contact-form">
<p id="feedback"><?php echo $feedback; ?></p>
<form action="?" methods="post">
    <ul>
        <li>
            <label for="name">Recpient:</label>
            <input type="text" readonly class="form-control" value="Contractor"/>
        </li>
        <br>
        <li>
            <label for="name">Name:</label>
            <input class="form-control" type="text" name="name" id="name" placeholder="Enter your name here"/>
        </li>
        <br>
        <li>
            <label for="name">Email:</label>
            <input class="form-control" type="text" name="email" id="email" placeholder="Enter your email here" />
        </li>
        <br>
        <li>
            <label for="name">Phone:</label>
            <input class="form-control" type="text" name="phone" id="phone" placeholder="Enter your phone number here" />
        </li>
        <br>
        <li>
            <label for="name">Message:</label>
            <textarea class="form-control" cols="42" rows="9" name="message" id="message" placeholder="Enter your full message here. Feel free to ask any question or send any of your inquiries through here."></textarea>
        </li>
        <br>
        <li>
            <input type="submit" value="Submit">
        </li>
    </ul>
</form>

那么在提交时我怎样才能发送电子邮件(包含上述变量)?我会回答您可能提供帮助的任何问题。

1 个答案:

答案 0 :(得分:0)

edit methods =“post”to method =“post”bro。

相关问题