-2

No idea why the header in the end is not redirecting to the thankyou.html page. I read similar previous posts but in most case people were simply using echo() instead of header() or something like that.

<?php  
if(isset($_POST['submit']))
{

$email_us = "info@pureazorestours.com";
$email_user = $_POST['email'];

$subject_us = "Website Reservation";
$subject_user = "Reservation request recieved";

$fname = $_POST['fname'];

$msg_us = '
<html>
<head>
<title>Website Reservation</title>
</head>
<body>
<p>RESERVATION DETAILS:</p>
<table>
    <tr>
        <td>Name:</td>
        <td>'.htmlspecialchars($fname).'</td>
    </tr>
    <tr>
        <td>Email:</td>
        <td>'.htmlspecialchars($_POST['email']).'</td>
    </tr>
    <tr>
        <td>Tour:</td>
        <td>'.htmlspecialchars($_POST['tname']).'</td>
    </tr>
    <tr>
        <td>Reservation Date:</td>
        <td>'.htmlspecialchars($_POST['datetour']).'</td>
    </tr>
    <tr>
        <td>Group Size:</td>
        <td>'.htmlspecialchars($_POST['groupsize']).'</td>
    </tr>
    <tr>
        <td>Pick-up Accommodation:</td>
        <td>'.htmlspecialchars($_POST['fpickup']).'</td>
    </tr>
    <tr>
        <td>Optional Message:</td>
        <td>'.htmlspecialchars($_POST['feedback']).'</td>
    </tr>
</table>
</body>
</html>
';

$msg_user = '
<html>
<head>
<title>Pure Azores Tours Reservation Request</title>
</head>
<body>
<p>Dear '.htmlspecialchars($fname).'</p>
<p>Thank you for submitting a reservation with Pure Azores Tours!
<p>Please expect an email from us confirming your reservation within the         next few hours. 
We usually respond in a few minutes!

<p>RESERVATION DETAILS:</p>
<table>
    <tr>
        <td>Name:</td>
        <td>'.htmlspecialchars($fname).'</td>
    </tr>
    <tr>
        <td>Email:</td>
        <td>'.htmlspecialchars($_POST['email']).'</td>
    </tr>
    <tr>
        <td>Tour:</td>
        <td>'.htmlspecialchars($_POST['tname']).'</td>
    </tr>
    <tr>
        <td>Reservation Date:</td>
        <td>'.htmlspecialchars($_POST['datetour']).'</td>
    </tr>
    <tr>
        <td>Group Size:</td>
        <td>'.htmlspecialchars($_POST['groupsize']).'</td>
    </tr>
    <tr>
        <td>Pick-up Accommodation:</td>
        <td>'.htmlspecialchars($_POST['fpickup']).'</td>
    </tr>
    <tr>
        <td>Optional Message:</td>
        <td>'.htmlspecialchars($_POST['feedback']).'</td>
    </tr>
</table>
</body>
</html>
';

$headers_us = "MIME-Version: 1.0" . "\r\n";
$headers_us .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers_user = "MIME-Version: 1.0" . "\r\n";
$headers_user .= "Content-type:text/html;charset=UTF-8" . "\r\n";

$headers_us .= 'From: <'.$_POST['email'].'>' . "\r\n";
$headers_user .= 'From: <info@pureazoretours.com>' . "\r\n";

mail($email_us,$subject_us,$msg_us,$headers_us);
mail($email_user,$subject_user,$msg_user,$headers_user);
header('Location: thankyou.html');
exit;
}
?>

EDIT: HTML code

    <div class="wrap-form">
    <form action="" method="post">

    <label>
         <span>Name:</span><input id="fname" type="text" placeholder="Your Name" name="fname" required />
    </label>
    <label>
        <span>Email:</span><input id="email" type="text" placeholder="Your Email" name="email" required />
    </label>
    <label> 
        <span>Tour</span>
        <select name="tname" required>
        <optgroup label="Day Tours">
            <option value="West São Miguel" <?php if($_GET['title'] == 'dt01'){ ?>selected="selected"<?php } ?>> - West São Miguel</option>
            <option value="A Day at Furnas Valley" <?php if($_GET['title'] == 'dt02'){ ?>selected="selected"<?php } ?>>  - A Day at Furnas Valley</option>
            <option value="Nordeste with Canyoning" <?php if($_GET['title'] == 'dt03'){ ?>selected="selected"<?php } ?>> - Nordeste with Canyoning</option>
        </optgroup>
        <optgroup label="Hiking Tours">
            <option value="Pico da Vara climb" <?php if($_GET['title'] == 'ht01'){ ?>selected="selected"<?php } ?>> - Pico da Vara Climb</option>
        </optgroup>
        <optgroup label="Multi-Day Packages">
            <option value="São Miguel Essential 2 days" <?php if($_GET['title'] == 'pa01'){ ?>selected="selected"<?php } ?>> - São Miguel Essential 2 days</option>
        </optgroup>

        </select>
    </label>

    <table>
            <tr>
                <td>
                    <label>
                    <span>Tour Date:</span><input style="width:130px" id="datepicker" type="text" name="datetour" required readonly/>
                    </label>
                </td>
                <td style="text-align: right">
                    <label>
                    <span>Group Size:</span><input style="width:56px; text-align:center" id="groupsize" type="number" name="groupsize" min="1" required value="2" />
                    </label>
                </td>
            </tr>
    </table>
    <label>
        <span class="clear">Pick-up accommodation:</span>
        <input id="fpickup" type="text" placeholder="Your Accommodation" name="fpickup" />
    </label>
    <label>
        <span>Message</span>
        <textarea id="feedback" placeholder="(Optional Text)" name="feedback"></textarea>
        <input type="submit" name="submit" id="submit" value="Submit" required/>
    </label>

    </form>
</div>

1 Answers1

1

Two common problems here. Firstly, you might have output prior to the header() function. This could be any whitespace or HTML prior to the PHP code. You cannot have anything output to the page, even a single whitespace, otherwise PHP will give you a 'headers already sent' message. You should have error reporting turned on as Jay pointed out.

Secondly, check the thankyou.html file actually exists and is in the same directly as the file above, with exactly the same file name and extension.

HenryTK
  • 1,287
  • 8
  • 11
  • I did what you guys suggest. This the warning I get: Cannot modify header information - headers already sent by (output started at /home/fy1jmqyz/public_html/pureazores.com/en/contact.php:124) in /home/fy1jmqyz/public_html/pureazores.com/en/contact.php on line 347 I have some code on this page that gets a 'title' variable to change the pre-selection on a drop-down menu. I wonder if that's cusing the problem. I'll edit OP with the html. – Miguel Soares Jan 25 '16 at 16:35
  • @MiguelSoares, google first: http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – trincot Jan 25 '16 at 16:38