Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

php form response

Status
Not open for further replies.
Joined
Jun 1, 2010
Posts
552
Reaction score
2
I don't have any clue about php really so if anyone could give a layman's answer that would be awesome. I've got a contact form, got it all styled as I want, but on submit it currently prints a response, unformatted, on a white page (code below).

if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }

How could I change this to to make it a bit more sophisticated? I don't really want to use js, is there a php solution? Either a pop up to confirm it was/wasn't sent or ideally printing those statements somewhere on the page with the form, as opposed to unformatted on a separate page?
 
Could do, what would the code be dude? I tried sending it back to the homepage before and it didn't work for some reason
 
That's what I tried and it didn't work, I must have put it in the wrong place. Could you give it in context to the rest of the code? Is this right?

if($sent)
{header('Location: http://www.example.com/'); }
else
{print "We encountered an error sending your mail"; }

I literally know sod all php, apologies.
 
Try it like this

Code:
<?php
if($sent)
header('Location: [URL]http://stackoverflow.com'[/URL]);
else 
{print "We encountered an error sending your mail"; } 
?>

Is there other code on your page before this as it wont work if there is
 
This is as it is on site, so yeh there is code before it. Would it work if I brought the if and else statements to the top as you've done, and put the the rest below it? Appreciate the help guys, cheers.

Code:
<?php 
 $to = "[email protected]"; 
 $subject = "Contact Us"; 
 $name = $_REQUEST['name'] ;
 $email = $_REQUEST['email'] ; 
 $message = $_REQUEST['message'] ; 
 $headers = "From: $email"; 
 $sent = mail($to, $subject, $message, $headers) ; 
 if($sent)
 header('Location: http://stackoverflow.com'); 
 else 
 {print "We encountered an error sending your mail"; }
 ?>
 
If thats all is on the page it should work I think. There is no blank lines or any other text before the code is there
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom