我在表单的action标签中写'#',然后包含一个php脚本来执行点击提交按钮的操作。
HTML code:
<form id="newsletter" method="post" action="#">
<div class="input-group">
<label class="sr-only" for="news">Full Name</label>
<input type="email" id="news" name="news" class="form-control" placeholder="E-Mail Address" required>
<span class="input-group-btn">
<button class="btn btn-default" type="submit" name="submit">Subscribe</button>
</span> </div>
</form>
<?php include "newsletter.php"?>
我希望在完成工作后将索引页面重定向到其他页面。 header [Location]似乎没有工作,因为它给出了已经发送的头的错误。
php代码:
<?php
if($_POST){
$email = $_POST["news"];
$subject = "New Subscribe for Newsletter";
$message = "<b>From : ".$email."</b><br/>";
$message = "<b>Subscriber from mailnews: $email</b>";
$from = "contact@email.com";
$to = "mailnews@email.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: MailNews<'.$to.'>' . "\r\n";
$headers .= 'From: Contacted from <'.$from.'>' . "\r\n";
mail($to, $subject, $message, $headers);
?>
<?php }
?>
答案 0 :(得分:0)
在php的最顶层包含函数
<?php
Ob_start();
?>
现在你不应该已经发送标头错误。确保它是你打开php标签后的第一件事。