PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
doncorleone
Forum Newbie
Posts: 2 Joined: Fri May 15, 2009 10:58 am
Post
by doncorleone » Fri May 15, 2009 11:13 am
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">
<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!
Last edited by
Benjamin on Fri May 15, 2009 12:11 pm, edited 1 time in total.
Reason: Changed code type from text to html, php.
ldougherty
Forum Contributor
Posts: 103 Joined: Sun May 03, 2009 11:39 am
Post
by ldougherty » Fri May 15, 2009 11:34 am
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.
Last edited by
Benjamin on Fri May 15, 2009 12:11 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Fri May 15, 2009 12:12 pm
I recommend using braces in control structures, for numerous reasons.
doncorleone
Forum Newbie
Posts: 2 Joined: Fri May 15, 2009 10:58 am
Post
by doncorleone » Fri May 15, 2009 12:29 pm
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?
crazycoders
Forum Contributor
Posts: 260 Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada
Post
by crazycoders » Fri May 15, 2009 12:33 pm
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!