Viewing php msg on the HTML page

advertisements

i am working on one static website, in which there is a contact us page. Here what i want to do is when the contact form is submitted it should show the message that - Email has been sent successfully. But the problem is i am calling the html page and we cannot pass php message in html view. So is there any way to get it done. conatctus.php

<?php
$error = '';

$mailTo = $_POST['email'];
$mailFrom = '[email protected]';
//$headers  = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$fullname = $_POST['username'];
$phoneno = $_POST['mobile'];
$emailaddress = $_POST['email'];
$msgsubject =$_POST['message'];
$new = "\n";
$msg =  $fullname.$new.$emailaddress.$new.$phoneno.$new.$msgsubject;

$to      = $email;
    $subject = 'Inquiry';
    $messageclient = '<div>

<p>Thank you For Inquiry.</p>
<p> We will reach back to you shortly. Have a Nice Day!</p>
<p>Company © 2013</p>
</p></div>
';
    $headers = 'From: [email protected]' . "\r\n" .
        'Reply-To: [email protected]' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "From: Company<[email protected]>\r\n";
    //$res = mail($to, $subject, $message, $headers);

//$message ='Thank you For Inquiry. We will reach back to you shortly. Have a Nice Day';
mail( $mailTo , $subject,  $messageclient, $headers);

$message .= "<p>Name: $fullname</p><br /><p>Contact Number : $phoneno</p><br />        <p>Email: $emailaddress</p><br /><p>Message: $msgsubject</p>";

mail( $mailFrom, $subject,$message, $headers); 

header("location:home.html");
?>

Your help is much appreciated, thanks in advance.


There are a lot of problems here, but to answer your question, you can't redirect after content has been sent.

If you add ob_start() to the top of the page it will buffer the contents and allow the redirect.

Upon, further re-reading of your post, maybe I misinterpreted. It doesn't look like you are sending content which means that your redirect IS working, but what you want is to add a message after it's been redirected.

You have options.

  1. Redirect to a static HTML page that reflects the message you want to convey.
  2. Redirect to a PHP page that has the logic to give the user a message.
  3. Use Ajax to send the email and don't redirect at all.