我想要做的是将提交的姓名、邮箱和消息发送到我的php脚本,然后发送邮箱消息.问题是我的表单操作没有触发,而是重新加载页面.
UPDATE个 我不知道我在这里的html表单中遗漏了什么:
<form method="post" action="">
<div class="input-group">
<input type="text" id="name" name="name" class="input-demo" placeholder="Your Name">
<span id="invalid-name">
Please enter at least 2 chars
</span>
</div>
<div class="input-group">
<input id="email" type="email" name="email" class="input-demo" placeholder="Email Address">
<span id="invalid-email">
Please enter valid email
</span>
</div>
<div class="input-group">
<textarea id="message" name="message" placeholder="Message">
</textarea>
<span id="invalid-message">
Please write something for us
</span>
</div>
<div>
</div>
<input type="submit" name="submit" value="Book a Demo">
</form>
UPDATE
PHP脚本首先获取值并构造邮箱消息,然后最后发送:
<?php
if (isset($_POST['submit'])) {
include 'index.php';
$to = "email@example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to, $subject, $message, $headers);
mail($from, $subject2, $message2, $headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
} else {
echo 'isset was false';
}
?>
这是我的文件夹 struct
我在本地主机ubuntu apache服务器上运行这个程序.