Link to home
Start Free TrialLog in
Avatar of raw_enha
raw_enha

asked on

PHP Coding

hi,

Well Im creating  service request and contact us page that once you input the required information you can confirm that it is correct and then it'll send you to a different page that states "your message has been received" . Unfortunately the message "your message has been received " is shown on the confirmation page... this is the coding:



<div id="content" style="width: 942px; height: 887px">
      <div align="center">
        <div align="right"><html>
<title></title>
<body>

<?php
if (isset($_POST["confirm"]) && $_POST["confirm"] != "")
  {
      $msg =  "First Name: ".$_POST["FirstName"]."\n";
      $msg .= "Last Name: ".$_POST["LastName"]."\n";
      $msg .= "Address: ".$_POST["Address"]."\n";
        $msg .= "Address2: ".$_POST["Address2"]."\n";
      $msg .= "City:".$_POST["City"]."\n";
        $msg .= "State:".$_POST["State"]."\n";
        $msg .= "Zip Code:".$_POST["PostCode"]."\n";
        $msg .= "Telephone:".$_POST["Tel"]."\n";
        $msg .= "Work Tel:".$_POST["WorkTel"]."\n";
        $msg .= "Mobile:".$_POST["Mobile"]."\n";
        $msg .= "Fax:".$_POST["Fax"]."\n";
        $msg .= "Company Name:".$_POST["Company2"]."\n";
        $msg .= "Type of Service:".$_POST["company2"]."\n";
 
      $recipient = "sales@andrewsxray.com";
      $subject = "Service Request";

      $mailheaders = "From:".$_POST["email"]."\n";
      $mailheaders .= "Reply-To:".$_POST["email"]."\n\n";

      if(mail($recipient, $subject, $msg, $mailheaders))
           echo "<b> <center>Your request has been sent successfully!</center> </b>";
      else
           echo "<b> Error in sending mail to ".$recipient."! </b>";
  }

else
   {
// validation
$validationOK=true;
if (Trim($FirstName)=="") $validationOK=false;
if (Trim($LastName)=="") $validationOK=false;
if (Trim($Address)=="") $validationOK=false;
if (Trim($City)=="") $validationOK=false;
if (Trim($State)=="") $validationOK=false;
if (!is_numeric($Tel)) $validationOK=false;
if (Trim($company2)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=Confirmationno.htm\">";
  exit;
}
}



?>

<h2 align="center"><br />
Thank you for filling out the service request...Please confirm your request!</h2>

<form method="post" action="">

<blockquote>
  <blockquote>
    <blockquote>
      <blockquote>
        <blockquote>
          <blockquote>
            <blockquote>
              <blockquote>
                <p align="justify"><strong>First Name:</strong> <?php echo $_POST['FirstName']; ?> </p>
                <p align="justify"><strong>Last Name:</strong> <?php echo $_POST['LastName']; ?> </p>
                <p align="justify"><strong>Address:</strong> <?php echo $_POST['Address']; ?> </p>
                        <p align="justify"><strong>Address2:</strong> <?php echo $_POST['Address2']; ?> </p>
                <p align="justify"><strong>City:</strong> <?php echo $_POST['City']; ?> </p>
                        <p align="justify"><strong>State:</strong> <?php echo $_POST['State']; ?> </p>
                        <p align="justify"><strong>Zip Code:</strong> <?php echo $_POST['PostCode']; ?> </p>
                        <p align="justify"><strong>Tel:</strong> <?php echo $_POST['Tel']; ?> </p>
                        <p align="justify"><strong>Work Tel:</strong> <?php echo $_POST['WorkTel']; ?> </p>
                        <p align="justify"><strong>Mobile:</strong> <?php echo $_POST['Mobile']; ?> </p>
                        <p align="justify"><strong>Fax:</strong> <?php echo $_POST['Fax']; ?> </p>
                        <p align="justify"><strong>Company Name:</strong> <?php echo $_POST['Company2']; ?> </p>
                         <p align="justify"><strong>Service Type:</strong> <?php echo $_POST['company2']; ?> </p>
              </blockquote>
            </blockquote>
          </blockquote>
        </blockquote>
      </blockquote>
    </blockquote>
  </blockquote>
</blockquote>
<input type="hidden" name="FirstName" value="<?php  echo $_POST['FirstName']; ?>" >
<input type="hidden" name="LastName" value="<?php  echo $_POST['LastName']; ?>" >
<input type="hidden" name="Address" value="<?php  echo $_POST['Address']; ?>" >
<input type="hidden" name="Address2" value="<?php  echo $_POST['Address2']; ?>" >
<input type="hidden" name="City" value="<?php  echo $_POST['City']; ?>" >
<input type="hidden" name="State" value="<?php  echo $_POST['State']; ?>" >
<input type="hidden" name="PostCode" value="<?php  echo $_POST['PostCode']; ?>" >
<input type="hidden" name="Tel" value="<?php  echo $_POST['Tel']; ?>" >
<input type="hidden" name="WorkTel" value="<?php  echo $_POST['WorkTel']; ?>" >
<input type="hidden" name="Mobile" value="<?php  echo $_POST['Mobile']; ?>" >
<input type="hidden" name="Fax" value="<?php  echo $_POST['Fax']; ?>" >
<input type="hidden" name="Company2" value="<?php  echo $_POST['Company2']; ?>" >
<input type="hidden" name="company2" value="<?php  echo $_POST['company2']; ?>" >

                      <p><form>
                       
 
                        <center>
                          <input type=button value="Back"
onCLick="history.back()">
                          <input type="submit" name="confirm" value="Confirm Request" />
                          <?php
                                      {
}
?>
                          </p>
</center>
                          </form>


How do I get the :

 if(mail($recipient, $subject, $msg, $mailheaders))
           echo "<b> <center>Your request has been sent successfully!</center> </b>";
      else
 

to show up on a separate page..?
Avatar of richswyatt
richswyatt

You want to be forwarded to another page and then the message "Your request has been sent successfully!", correct?

If that is the case then do this:

if(mail($recipient, $subject, $msg, $mailheaders))
   header("location: success.html"); // or whatever you want to call it

and make sure that message is shown in the html of that page.

Am I on track with what you are looking for?
Avatar of raw_enha

ASKER

its good... it tells me :

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/psa/home/vhosts/andrewsxray.com/httpdocs/actionpage4.php:10) in /usr/local/psa/home/vhosts/andrewsxray.com/httpdocs/actionpage4.php on line 60


what does that mean?

     $recipient = "sales@andrewsxray.com";
      $subject = "Service Request";

      $mailheaders = "From:".$_POST["email"]."\n";
      $mailheaders .= "Reply-To:".$_POST["email"]."\n\n";

if(mail($recipient, $subject, $msg, $mailheaders))
   header("location: confirm.html");
      else
           echo "<b> Error in sending mail to ".$recipient."! </b>";
  }

else


this is how I inputed it
It means that you are sending output to the page prior to the call of header();

Get rid of any output prior to the call of that function.
perhaps get rid of

<div id="content" style="width: 942px; height: 887px">
      <div align="center">
        <div align="right"><html>
<title></title>
<body>
well... after removing the div id coding it still tells me this:


Warning: Cannot modify header information - headers already sent by (output started at /usr/local/psa/home/vhosts/andrewsxray.com/httpdocs/actionpage4.php:10) in /usr/local/psa/home/vhosts/andrewsxray.com/httpdocs/actionpage4.php on line 56
is the code above the entire coding for actionpage4.php ?

At line 10 of actionpage4.php is some output that is interfering with the header() call.

What is at line 10?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<STYLE TYPE="text/css">
a:link { color: #000000; text-decoration: none }
a:active { color: #000000; text-decoration: none }
a:visited { color: #000033; text-decoration: none }
a:hover { color: green; text-decoration: underline }
</STYLE>
<link rel="shortcut icon" href="images/lettera.ico" />
</head>
<body>
<div id="header" style="width: 877px; height: 91px">
      <h1>Andrews X-Ray, Inc.</h1>
      <br><br>
            <a accesskey="1" href="index1.html">Home</a>
            <a accesskey="2" href="xrayproducts.html">Products</a>
            <a accesskey="3" href="xrayservice.html">Services</a>
            <a accesskey="4" href="aboutus.html">About us</a>
            <a accesskey="5" href="#">Contact us</a>
      <br>
      <br>
</div>


<?php
if (isset($_POST["confirm"]) && $_POST["confirm"] != "")
  {
      $msg =  "First Name: ".$_POST["FirstName"]."\n";
      $msg .= "Last Name: ".$_POST["LastName"]."\n";
      $msg .= "Address: ".$_POST["Address"]."\n";
        $msg .= "Address2: ".$_POST["Address2"]."\n";
      $msg .= "City:".$_POST["City"]."\n";
        $msg .= "State:".$_POST["State"]."\n";
        $msg .= "Zip Code:".$_POST["PostCode"]."\n";
        $msg .= "Telephone:".$_POST["Tel"]."\n";
        $msg .= "Work Tel:".$_POST["WorkTel"]."\n";
        $msg .= "Mobile:".$_POST["Mobile"]."\n";
        $msg .= "Fax:".$_POST["Fax"]."\n";
        $msg .= "Company Name:".$_POST["Company2"]."\n";
        $msg .= "Type of Service:".$_POST["company2"]."\n";
 
      $recipient = "sales@andrewsxray.com";
      $subject = "Service Request";

      $mailheaders = "From:".$_POST["email"]."\n";
      $mailheaders .= "Reply-To:".$_POST["email"]."\n\n";

if(mail($recipient, $subject, $msg, $mailheaders))
   header("location: confirm.html");
      else
           echo "<b> Error in sending mail to ".$recipient."! </b>";
  }

else
   {
// validation
$validationOK=true;
if (Trim($FirstName)=="") $validationOK=false;
if (Trim($LastName)=="") $validationOK=false;
if (Trim($Address)=="") $validationOK=false;
if (Trim($City)=="") $validationOK=false;
if (Trim($State)=="") $validationOK=false;
if (!is_numeric($Tel)) $validationOK=false;
if (Trim($company2)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=Confirmationno.htm\">";
  exit;
}
}



?>

<h2 align="center"><br />
Thank you filling out this service request...Please confirm your request!</h2>

<form method="post" action="">

<blockquote>
  <blockquote>
    <blockquote>
      <blockquote>
        <blockquote>
          <blockquote>
            <blockquote>
              <blockquote>
                <p align="justify"><strong>First Name:</strong> <?php echo $_POST['FirstName']; ?> </p>
                <p align="justify"><strong>Last Name:</strong> <?php echo $_POST['LastName']; ?> </p>
                <p align="justify"><strong>Address:</strong> <?php echo $_POST['Address']; ?> </p>
                        <p align="justify"><strong>Address2:</strong> <?php echo $_POST['Address2']; ?> </p>
                <p align="justify"><strong>City:</strong> <?php echo $_POST['City']; ?> </p>
                        <p align="justify"><strong>State:</strong> <?php echo $_POST['State']; ?> </p>
                        <p align="justify"><strong>Zip Code:</strong> <?php echo $_POST['PostCode']; ?> </p>
                        <p align="justify"><strong>Tel:</strong> <?php echo $_POST['Tel']; ?> </p>
                        <p align="justify"><strong>Work Tel:</strong> <?php echo $_POST['WorkTel']; ?> </p>
                        <p align="justify"><strong>Mobile:</strong> <?php echo $_POST['Mobile']; ?> </p>
                        <p align="justify"><strong>Fax:</strong> <?php echo $_POST['Fax']; ?> </p>
                        <p align="justify"><strong>Company Name:</strong> <?php echo $_POST['Company2']; ?> </p>
                         <p align="justify"><strong>Service Type:</strong> <?php echo $_POST['company2']; ?> </p>
              </blockquote>
            </blockquote>
          </blockquote>
        </blockquote>
      </blockquote>
    </blockquote>
  </blockquote>
</blockquote>
<input type="hidden" name="FirstName" value="<?php  echo $_POST['FirstName']; ?>" >
<input type="hidden" name="LastName" value="<?php  echo $_POST['LastName']; ?>" >
<input type="hidden" name="Address" value="<?php  echo $_POST['Address']; ?>" >
<input type="hidden" name="Address2" value="<?php  echo $_POST['Address2']; ?>" >
<input type="hidden" name="City" value="<?php  echo $_POST['City']; ?>" >
<input type="hidden" name="State" value="<?php  echo $_POST['State']; ?>" >
<input type="hidden" name="PostCode" value="<?php  echo $_POST['PostCode']; ?>" >
<input type="hidden" name="Tel" value="<?php  echo $_POST['Tel']; ?>" >
<input type="hidden" name="WorkTel" value="<?php  echo $_POST['WorkTel']; ?>" >
<input type="hidden" name="Mobile" value="<?php  echo $_POST['Mobile']; ?>" >
<input type="hidden" name="Fax" value="<?php  echo $_POST['Fax']; ?>" >
<input type="hidden" name="Company2" value="<?php  echo $_POST['Company2']; ?>" >
<input type="hidden" name="company2" value="<?php  echo $_POST['company2']; ?>" >

                      <p><form>
                       
 
                        <center>
                          <input type=button value="Back"
onCLick="history.back()">
                          <input type="submit" name="confirm" value="Confirm Request" />
                          <?php
                                      {
}
?>
                          </p>
</center>
                          </form>
<div id="footer" style="width: 887px; height: 1px">
      <p>
                                                            <a href="index1.html">
                                                            <font size="2" color="#000000">Home</font></a><font size="2"><font color="#000000">
                                                            -
                                                            <a href="companyspolicy.html">Company Policy</a>
                                                            -</font><font color="#29424a">                                                            <font color="#29424A">
                                                            <a href="xrayproducts.html">
                                                            <font color="#000000">Products</font></a></font></font><font color="#000000">
                                                            -
                                                            </font><font color="#29424a">
                                                            <a href="http://www.hudsondigitalsystems.com/">
                                                            <font color="#000000">Partners</font></a></font><font color="#000000">
                                                            -                                                            </font><a href="aboutus.html"><font color="#29424a">
                                                            <font color="#000000">About Us</font></font></a>      <font color="#000000">-
                                                            </font></font>
      <a href="contactus.html">
                                                            <font size="2" color="#000000">Contact
                                                            Us</font></a><font size="2" color="#000000">
                                                            -
                                                            </font>
                                                            <font color="#000000" size="2">Sitemap</font></p>
</div>
</body>
</html>



thats the whole coding
ASKER CERTIFIED SOLUTION
Avatar of richswyatt
richswyatt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cant I just modify the confirm button to generate the new page (confim.html)  instead of changing anything else?
Negative - you would need to change the action of the Form to a new page. PHP is finicky about the header() function when HTML or php echo() has been previously output to the screen prior to it.

The other thing you COULD do is move the whole IF block (if isset($_POST["confirm"]) etc....
to the VERY TOP of the page - prior to any HTML output
hi, well I'm still having my little issue for the confirmation page. I just need to get the page to generate the message "thankyou for your request it's been successfully sent" on another page.
Have you changed anything per the suggestions?
yeah I did richswyatt, but the problem is that I dont want to use javascript and that the "header" function is not working.
Yes - because you have some output prior to the header() function.

Strip out the $_POST handling from the current page - set the form to POST to a new PHP where you will handle the IF block and then have the header in the if block on the new page. This will ensure that there is NO output prior to the header() function.
<?php
if() with the header() function

?>
Its not functioning.. do you any good websites that can give you coding for forms and their confirmation page? maybe I just need to work with a new form.... this one is giving me trouble anyways.
Oh yes ! I figured it out...
Alright - what was the problem?
all I did was add this:


<form method="post" action= "confirm.html"> (Confirm.htmL to the form property. )

thankx for all you help though.
Ok - that works for the confirm.html - but how/where are you processing the $_POST?

(By the way - this is what I was suggesting in the first place.)
the same way as I was processing it before...