我以前处理过联系表单,但是这个表单没有提交到我的电子邮件中。我还尝试实现重定向URL到/contact。php
代码的问题是:我的电子邮件没有收到它。我的问题是:什么是不允许联系表单通过电子邮件?
<form id='contactus' action='index.php' method='post' accept-charset='UTF-8'>
<fieldset>
<div class="first-row">
<label for="name">Your Name</label>
<input type='text' class="input-large" name='name' id='name' value='' placeholder="Your Name" />
<label for="phone">Phone Number</label>
<input type='text' class="input-large" name='phone' id='phone' value='' placeholder="Phone Number" />
</div>
<div class="second-row">
<label for="email">Email Address</label>
<input type='text' class="input-large" name='email' id='email' value='' placeholder="Email Address" />
</div>
<div class="second-row">
<label for="business">Business</label>
<input type='text' class="input-large" name='business' id='business' value='' placeholder="Business" />
</div>
<label style="margin-left: 20px;" for="message">Message</label>
<textarea rows="10" class="input-xlarge" cols="50" name='message' placeholder="Message" id='message'></textarea>
<div class="clearfix"></div> /* Sorry I'm using Bootstrap */
<div><input type='submit' class="btn btn-primary" name='Submit' value='Submit' />
</div>
</fieldset>
</form>
<script type="text/php">
<?php
if(isset($_POST['submit'])) {
$to = "hello@geniusghost.com";
$subject = "Genius Ghost Contact Form";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$business = $_POST['business'];
$message = $_POST['message'];
$body = "From: $name'n Phone Number: $phone'n E-Mail: $email'n Business: $business'n'n Message:'n $message";
mail($to, $subject, $body);
}
?>
</script>
帮帮我!我知道你们可能经常遇到这些问题
您的$_POST['submit']
应该有一个大写的"S",因为您的提交按钮的名称是" submit "。
同样,你不需要在<script>
标签中包装PHP -只需要<?php ... ?>
代码:
<form id='contactus' action='index.php' method='post' accept-charset='UTF-8'>
<fieldset >
<div class="first-row">
<label for="name">Your Name</label>
<input type='text' class="input-large" name='name' id='name' value='' placeholder="Your Name" />
<label for="phone">Phone Number</label>
<input type='text' class="input-large" name='phone' id='phone' value='' placeholder="Phone Number" />
</div>
<div class="second-row">
<label for="email">Email Address</label>
<input type='text' class="input-large" name='email' id='email' value='' placeholder="Email Address" />
</div>
<div class="second-row">
<label for="business">Business</label>
<input type='text' class="input-large" name='business' id='business' value='' placeholder="Business" />
</div>
<label style="margin-left: 20px;" for="message">Message</label>
<textarea rows="10" class="input-xlarge" cols="50" name='message' placeholder="Message" id='message'></textarea>
<div class="clearfix"></div> /* Sorry I'm using Bootstrap */
<div>
<input type='submit' class="btn btn-primary" name='Submit' value='Submit' />
</div>
</fieldset>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "hello@geniusghost.com";
$subject = "Genius Ghost Contact Form";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$business = $_POST['business'];
$message = $_POST['message'];
$body = "From: $name'n Phone Number: $phone'n E-Mail: $email'n Business: $business'n'n Message:'n $message";
mail($to, $subject, $body);
}
?>
如果你有任何问题请告诉我!
谢谢
将name='Submit'
更改为name='submit'
。变量和表单元素是区分大小写的。
另外,丢掉<script type="text/php">
和</script>
使用$body = "From: $name'n
将导致From:
部分的mail header
格式不正确,并且您将永远无法直接回复给给您发电子邮件的人。
修复/修改并测试。
旁注:如果您在一个文件中使用此代码,请使用action=""
而不是action='index.php'
(在我的脚注下面有更多关于)
<form id='contactus' action='index.php' method='post' accept-charset='UTF-8'>
<fieldset >
<div class="first-row">
<label for="name">Your Name</label>
<input type='text' class="input-large" name='name' id='name' value='' placeholder="Your Name" />
<label for="phone">Phone Number</label>
<input type='text' class="input-large" name='phone' id='phone' value='' placeholder="Phone Number" />
</div>
<div class="second-row">
<label for="email">Email Address</label>
<input type='text' class="input-large" name='email' id='email' value='' placeholder="Email Address" />
</div>
<div class="second-row">
<label for="business">Business</label>
<input type='text' class="input-large" name='business' id='business' value='' placeholder="Business" />
</div>
<label style="margin-left: 20px;" for="message">Message</label>
<textarea rows="10" class="input-xlarge" cols="50" name='message' placeholder="Message" id='message'></textarea>
<div class="clearfix"></div> /* Sorry I'm using Bootstrap */
<div><input type='submit' class="btn btn-primary" name='submit' value='Submit' />
</div>
</fieldset>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "hello@geniusghost.com";
$subject = "Genius Ghost Contact Form";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$business = $_POST['business'];
$message = $_POST['message'];
$headers = "From: $name<$email>'r'n";
$body = "From: $name<$email>'r'n Phone Number: $phone'n E-Mail: $email'n Business: $business'n'n Message:'n $message";
mail($to, $subject, $body, $headers);
}
?>
脚注:
如果您不希望表单在提交后显示,如果是这种情况,使用以下命令:
旁注:这只会在PHP位于HTML之上并作为单个文件使用时才会起作用,如果你想使用这个方法的话。
<?php
if(isset($_POST['submit'])) {
$to = "hello@geniusghost.com";
$subject = "Genius Ghost Contact Form";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$business = $_POST['business'];
$message = $_POST['message'];
$headers = "From: $name<$email>'r'n";
$body = "From: $name<$email>'r'n Phone Number: $phone'n E-Mail: $email'n Business: $business'n'n Message:'n $message";
mail($to, $subject, $body, $headers);
echo "Thank you.";
echo "<a href='http://www.example.com/home.php'>Click here</a> to return to the home page.";
exit();
}
?>
<form id='contactus' action='' method='post' accept-charset='UTF-8'>
<fieldset >
<div class="first-row">
<label for="name">Your Name</label>
<input type='text' class="input-large" name='name' id='name' value='' placeholder="Your Name" />
<label for="phone">Phone Number</label>
<input type='text' class="input-large" name='phone' id='phone' value='' placeholder="Phone Number" />
</div>
<div class="second-row">
<label for="email">Email Address</label>
<input type='text' class="input-large" name='email' id='email' value='' placeholder="Email Address" />
</div>
<div class="second-row">
<label for="business">Business</label>
<input type='text' class="input-large" name='business' id='business' value='' placeholder="Business" />
</div>
<label style="margin-left: 20px;" for="message">Message</label>
<textarea rows="10" class="input-xlarge" cols="50" name='message' placeholder="Message" id='message'></textarea>
<div class="clearfix"></div> /* Sorry I'm using Bootstrap */
<div><input type='submit' class="btn btn-primary" name='submit' value='Submit' />
</div>
</fieldset>
</form>