1 Replies - 702 Views - Last Post: 23 February 2012 - 02:06 AM Rate Topic: -----

#1 blackfeather  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-February 12

Blank page after pressing Submit

Posted 23 February 2012 - 01:55 AM

I'm really really new to PHP. I wrote my form in HTML. When the user click on Submit the mail needs to automatically send and then redirect either to a thank you page or back to the contact us page.
 <form method="POST" action="contact.php">
                        Your Name:
                        <input type="text" name="name" style="width: 177px" /></p>
                        Email Address:
                        <input type="text" name="email" style="width: 160px" /></p>
                    <textarea name="message" rows="12" cols="30">Message</textarea><br />
                    <input type="submit" name="send" value="Submit" />

and my php looks like this:
 $to = "[email protected]"; 
 $subject = "Contact Us"; 
 $email = $_REQUEST['email'] ; 
 $message = $_REQUEST['message'] ; 
 $headers = "From: $email"; 
 $sent = mail($to, $subject, $message, $headers) ; 
 $loc = thankyou.htm
 header("Location: $loc");
 {print "We encountered an error sending your mail"; }

When clicking submit it just goes directly to contact.php and does not redirect back to the contact page. I have made $loc a variable, but have tried using the http:// path directly in the header as well. I even tried to incorporate javascript, but nothing seems to work. However when i just insert a print command instead of the header command it does work.

Can someone please give me some advice? I have googled this problem over and over and nothing seems to make sense or work.

This post has been edited by Dormilich: 23 February 2012 - 02:03 AM
Reason for edit:: protecting your inbox from spam

Is This A Good Question/Topic? 0
  • +

Replies To: Blank page after pressing Submit

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3980
  • View blog
  • Posts: 12,272
  • Joined: 08-June 10

Re: Blank page after pressing Submit

Posted 23 February 2012 - 02:06 AM

a) you're missing the quotes around thankyou.htm (that would have been mentioned in the emitted notices*, were they enabled)
b) why not including thankyou.htm directly instead of a redirect?
c) if you make a post request, use the $_POST superglobal, otherwise the posted variables can be overridden by attaching different values in the URL (which is no problem using e.g. Firebug)

* - you get 2 notices (undefined constant, assuming string) whose resulting strings are (coincidentally) concatenated by the . operator

This post has been edited by Dormilich: 23 February 2012 - 02:12 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1