Page 1 of 1

form to email php

Posted: Fri May 15, 2009 11:13 am
by doncorleone
hello ~ need some help with form to email php script. my goal is to set up a 'refer this page to a friend' form. im having a tough time trouble-shooting because it doesn't seem to be working, and i am a bit of a noob...
here is the form code:

Code: Select all

<form method="post" action="email.php">
&nbsp;<font face="Verdana" size="1">(A link will be included in your email)</font>
<p><font face="Verdana" size="1">Your email:<br>
<input type="text" name="sender" size="20"></font></p>
<p><font face="Verdana" size="1">Recipient's email:<br>
<input type="text" name="recipient" size="20"></font></p>
<p><font face="Verdana" size="1">Message: (optional)<br>
</font><textarea rows="5" name="message" cols="28"></textarea><br>
<input type="submit" value="Send" style="width: 44; height: 23"></p>
</form>
 
here is the php script:

Code: Select all

<?php 
$to = $_POST['recipient']; 
$subject = "market commentary"; 
$headers .= "Reply-To: " . $_POST['sender'] . "\r\n"; 
$headers .= "Return-Path: " . $_POST['sender'] . "\r\n";
$message = ("http://confidentiallink.net"); 
$message = $_POST['message']; 
mail($to, $subject, $message, $headers); 
// redirect back to url visitor came from
   header("Location: thankyou.html");
?>
any help is greatly appreciated!

Re: form to email php

Posted: Fri May 15, 2009 11:34 am
by ldougherty
Change your mail statement to this..

Code: Select all

 
  if(mail($to, $subject, $message, $headers))
    echo "<font color=blue><B>SUCCESS!</b></font> Email Successfully Sent to <b>$to</b><br><br>";
  else
    echo "Mail send failure - message not sent";
 
This will atleast tell you if the form itself is working or not.

Re: form to email php

Posted: Fri May 15, 2009 12:12 pm
by Benjamin
I recommend using braces in control structures, for numerous reasons.

Re: form to email php

Posted: Fri May 15, 2009 12:29 pm
by doncorleone
Thank you for the suggestion. I received an HTTP 500 internal server error...

Before, my form was leading to the redirect 'thankyou' page, but now it leads to the error page. The redirect would work, but an email was never sent to the recipient. (I tested it using my own email address as the sender and recipient.)

Any thoughts?

Re: form to email php

Posted: Fri May 15, 2009 12:33 pm
by crazycoders
Remove the error page redirect to see what the error really is and if using IE, disable simplified error messages so you actually see the content!