2015-11-11 27 views
0

我有一個表單,我工作得很好,但當我嘗試和重定向後表單提交到一個謝謝頁面,但獲取和錯誤的「無法修改標題信息 - 標題已發送」。我知道mail()部分的標題正在修改中,但是如何在沒有錯誤的情況下執行此操作?php重定向後郵件發送頭錯誤

代碼:

<?php 
//if "email" variable is filled out, send email 
    if (isset($_REQUEST['email'])) { 

    function died($error) { 
     // your error code can go here 
     echo "We are very sorry, but there were error(s) found with the form you 
     submitted. "; 
     echo "These errors appear below.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['first_name']) || 
     !isset($_POST['last_name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['phone'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 

    //Form Variables 
    //Personal Information 
    $subject = "Smile Guide"; 
    $email = $_REQUEST['email']; 
    $first_name = $_REQUEST['first_name']; 
    $last_name = $_REQUEST['last_name']; 
    $phone = $_REQUEST['phone']; 
    $admin_email = "[email protected],$email"; 

    //Stage 1 
    $chipped = $_REQUEST['smile-fault-1']; 
    $color = $_REQUEST['smile-fault-2']; 
    $gaps = $_REQUEST['smile-fault-3']; 
    $worn = $_REQUEST['smile-fault-4']; 
    $crooked = $_REQUEST['smile-fault-5']; 
    $metal = $_REQUEST['smile-fault-6']; 

    //Stage 2 
    $aggressive = $_REQUEST['smile-prefered-1']; 
    $mature = $_REQUEST['smile-prefered-2']; 
    $vigorous = $_REQUEST['smile-prefered-3']; 
    $dominant = $_REQUEST['smile-prefered-4']; 
    $focused = $_REQUEST['smile-prefered-5']; 
    $enhanced = $_REQUEST['smile-prefered-6']; 
    $soften = $_REQUEST['smile-prefered-7']; 
    $hollywood = $_REQUEST['smile-prefered-8']; 
    $functional = $_REQUEST['smile-prefered-9']; 
    $natural = $_REQUEST['smile-prefered-10']; 
    $youthful = $_REQUEST['smile-prefered-11']; 
    $oval = $_REQUEST['smile-prefered-12']; 

    //Stage 3 
    $shade = $_REQUEST['smile-color']; 

    //List errors 
    $error_message = ""; 
     $string_exp = "/^[A-Za-z0-9 .'-]+$/"; 
     if(!preg_match($string_exp,$first_name)) { 
     $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
     } 
     if(!preg_match($string_exp,$last_name)) { 
     $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
     } 
     $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
     if(!preg_match($email_exp,$email)) { 
     $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
     } 
     if(!preg_match($string_exp,$phone)) { 
     $error_message .= 'The Phone Number you entered does not appear to be valid.<br />'; 
     } 
     if(strlen($error_message) > 0) { 
     died($error_message); 
     }  

    //The Message 
    $content = '<html><body><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center">'; 
    $content .= '<img src="http://smiletothemaxdentallab.com/guide/smile-logo.jpg" style="display: block; margin: 10px auto;">'; 
    $content .= '<h1 style="color: #c51f4f;">Smile Guide</h1>'; 
    $content .= "<h2 style='background-color:#c51f4f; color:#fff; padding:10px 0;'>Client Information</h2><ul style='list-style-type: none; color:#999999;'>"; 
    $content .= "<li>Name:".$last_name.",".$first_name."</li>"; 
    $content .= "<li>Phone:".$phone."</li>"; 
    $content .= "<li>Email:".$email."</li>"; 
    $content .= "</ul>"; 
    $content .= "<h2 style='background-color:#c51f4f; color:#fff; padding:10px 0;'>Current Teeth Issues</h2><ul style='list-style-type: none; color:#999999;'>"; 
    $content .= isset($_POST['smile-fault-1']) ? "<li>".$chipped."</li>" : ""; 
    $content .= isset($_POST['smile-fault-2']) ? "<li>".$color."</li>" : ""; 
    $content .= isset($_POST['smile-fault-3']) ? "<li>".$gaps."</li>" : ""; 
    $content .= isset($_POST['smile-fault-4']) ? "<li>".$worn."</li>" : ""; 
    $content .= isset($_POST['smile-fault-5']) ? "<li>".$crooked."</li>" : ""; 
    $content .= isset($_POST['smile-fault-6']) ? "<li>".$metal."</li>" : ""; 
    $content .= "</ul>"; 
    $content .= "<h2 style='background-color:#c51f4f; color:#fff; padding:10px 0;'>Desired Color</h2><ul style='list-style-type: none; color:#999999;'>"; 
    $content .= "<li>".$shade."</li>"; 
    $content .= "</ul>"; 
    $content .= "</td></tr><tr><td style='background-color:#F7F7F7; color:#999999; text-align:center; padding: 50px 0;'><p>Brought to you be AOC Dental Lab</p><p>Toll free (800) 729-1593</p><p>1724 E Sherman Ave | Coeur d’Alene, Idaho | 83814</p>"; 
    $content .= "</td></tr></table></body></html>"; 

    //Set up Header 
    $headers = "From: " . strip_tags($_POST['email']) . "\r\n"; 
    $headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n"; 
    $headers .= 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

    //Send Email 
    $send = mail($admin_email, $subject, $content, $headers); 

    if($send) { 
     header("Location: http://website.com/smile-guide/thank-you"); 
    } 

} 

?> 
+0

放置一個''出口重定向,而不是()和渲染你的頁面。使用Ctrl + U打開源代碼,並確保您的html之前或中間沒有任何空格或其他符號 – Croll

回答

0

此錯誤是由事實,你已經在此刻發送數據到客戶端,您要發送的報頭(應該先發送)引起的。

檢查您的頁面編碼。也許它是UTF-8 +(與UTF-8 signature

如果不是,那麼你需要檢查空格。

0

不要忘了退出後重定向

if($send) { 
    header("Location: http://website.com/smile-guide/thank-you"); 
    exit(); 
}