Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. Share your own thoughts and experience, accounts may be terminated for violations.
  • Welcome to AcornDomains.co.uk, a friendly community for UK domain investors, developers and anyone interested in domain names.

    Whether you're looking to buy or sell domains, learn more about the UK domain market, get feedback on your names, or simply chat with other domainers, you're in the right place. AcornDomains has been bringing together people from across the UK domain industry for many years, from complete beginners to experienced investors.

    Have a look around, join the discussions and, if you haven't already, create a free account and introduce yourself.

php form response

Status
Not open for further replies.
Joined
Jun 1, 2010
Posts
548
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.
Top Bottom