为什么这个PHP表单没有提交给电子邮件?

时间:2016-08-07 18:42:57

标签: php html forms

这是完整的代码,上面的部分是PHP代码,下面是表单,我试图在GMAIL ID上发送邮件,我已经为每个元素添加了正确的名称,请你帮我纠正错误或者用这个问题形式。

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'abcd@gmail.com';
$subject = 'Hello';

$body = "From: $name\n E-Mail: $email\n Message:\n $message"; 

if ($_POST['submit']) {
if (mail ($to, $subject, $body)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
}
} ?>

<form method="post" action="form.php">

<label>Name</label>
<input name="name" placeholder="Type Here">

<label>Email</label>
<input name="email" type="email" placeholder="Type Here">

<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>

<input id="submit" name="submit" type="submit" value="Submit">

</form>

0 个答案:

没有答案