我的PHP电子邮件代码有什么问题;它不会重定向到感谢页面

时间:2014-01-18 21:41:06

标签: php forms

好奇以下php代码在填写并提交联系表单时发送电子邮件有什么问题。电子邮件完美到达,但不是重定向,而是出现以下错误:

警告:无法修改标题信息 - 已在/ home4 / ranchoba / public_html / marvan / marvan /中发送的输出(/home4/ranchoba/public_html/marvan/marvan/send.php:1中的输出)第112行发送.php

我尝试通过表单中的操作调用php文件,并在页面的第一行放置一个。两者都不起作用。

PHP代码:

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
//if the form is submitted, go ahead and send the email to ops
ob_start();

if ($_POST['is_form_submitted'] == "yes")
{
//Send email to ops of this request-----------------------------------------------------------------------------------

// multiple recipients

$to = 'blah@gmail.com';

// subject

$subject = "Contact Request: ".$_POST['name'];

// message
$message = '
<html>
<head>
<title>Re: Marvan Site Contact Request</title>
<style type="text/css">
<!--
.style4 {font-family: Arial, Helvetica, sans-serif; font-size: 12; }
.style5 {font-size: 12}
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 12; font-weight: bold; }
-->
</style>
</head>
<body>';
$message=$message.'
<table width="450" border="0" align="center" cellpadding="4" cellspacing="0" style="border-color:#CCCCCC; border-style:solid; border-width:1px; background-color:#FFFFFF; padding-top:3px;">&nbsp;
  <tr>
    <td width="430" style="height:auto;" valign="top">';

$message=$message.'<img src="http://www.blah.com/blah/images/logo.png">';

$message=$message.'<hr>';

$message=$message.'<h2 style="font-family:Arial, Helvetica, sans-serif; color:#B58736">Contact Request </h2>';

$message=$message.'
<table width="486" border="0" align="center" cellpadding="4" cellspacing="2">
      <tr>
        <td colspan="4" valign="top"><div align="left" class="style4"><span style="color:#000000; font-weight:bold;">Contact Details: </span></div></td>
        </tr>

      <tr>
        <td width="145" valign="top"><div align="left" class="style4">Name :</div></td>
        <td width="1" valign="top"><span class="style5"></span></td>
        <td width="984" colspan="2" valign="top"><div align="left" class="style6">';
          $message = $message. $_POST['name'];
          $message = $message.'</div></td>
      </tr>
      <tr>
        <td valign="top"><div align="left" class="style4">Email :</div></td>
        <td valign="top"><span class="style5"></span></td>
        <td colspan="2" valign="top"><div align="left" class="style6">';
          $message = $message. $_POST['email'];
          $message = $message.'</div></td>
      </tr>
      <tr>
        <td valign="top"><div align="left" class="style4">Subject :</div></td>
        <td valign="top"><span class="style5"></span></td>
        <td colspan="2" valign="top"><div align="left" class="style6">';
          $message = $message. $_POST['subject'];
          $message = $message.'</div></td>
      </tr>
      <tr>
        <td valign="top"><div align="left" class="style4">Phone :</div></td>
        <td valign="top"><span class="style5"></span></td>
        <td colspan="2" valign="top"><div align="left" class="style6">';
          $message = $message. $_POST['phone'];
          $message = $message.'</div></td>
      </tr>                     
      <tr>
        <td valign="top"><div align="left" class="style4">Message :</div></td>
        <td valign="top"><span class="style5"></span></td>
        <td colspan="2" valign="top"><div align="left" class="style6">';
          $message = $message. $_POST['message'];
          $message = $message.'</div></td>
      </tr>';

$message = $message.'         
      <tr> <tr><td colspan="4" valign="top"><span class="style5"></span></td>
        </tr>'; 
$message = $message.' 
    </table>    
    <br /></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
/*              $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";*/
/*              $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";*/

// Mail it
mail($to, $subject, $message, $headers);
//end of Send Email to Client -------------------------------------------------------------- 

//redirect to the thank you page
header('Location: http://www.blah.com/blah/thank-you.php');

} //end of if ($_POST['is_form_submitted'] == "yes")
?>

2 个答案:

答案 0 :(得分:0)

也许在脚本中<?php标记之前有空格。请检查并删除它们。也可以使用没有BOM的UTF-8文件编码

答案 1 :(得分:0)

最好找到输出导致header()失败的空格或行的位置。但是如果你不能,请尝试在header()之前清除缓冲区。

        if (ob_get_length() > 0 ) {
            ob_clean();
            flush();
        }