leprakawn
04-24-2004, 03:25 AM
Okay, I've used HTML since '96, but I'm just now starting with PHP... obviously I've been too busy with school!
I have a form that asks for name, e-mail and provides two radio buttons (un/subscribe). I've tried the if statement, but I can't figure out what I'm doing wrong. Any help will be greatly appreciated!
Form:
<form action="newsletter.php" method="post" name="form">
<tr><td align=center colspan=2><font size=2><b>Free Newsletter</b></font></td></tr>
<tr><td>Name:</td><td><input type="text" name="name" size="24" maxlength="25" value=""></td></tr>
<tr><td>E-mail:</td><td><input type="text" name="email" size="24" maxlength="30" value=""></td></tr>
<tr><td colspan=2 align=center><input type="radio" name="choice" value="sub" checked>Subscribe <input type="radio" name="choice" value="unsub">Unsubscribe</td></tr>
<tr><td colspan=2 align=center><input type="submit" value="Submit"> </td></tr>
</form>
PHP:
<?
$name=$_POST['name'];
$email=$_POST['email'];
$to="leprakawn@hotmail.com";
$message="$name came to the site. E-mail: $email\n";
if ($choice == "sub") {$message = $message "Subscribed"; }
if ($choice == "unsub") {$message .= "Not Subscribed"; }
if(mail($to,"Newsletter Sub/Unsub",$message,"From: $email\n")) {
echo "Thank you for your interest. We will update our list depending on your choice.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
I have a form that asks for name, e-mail and provides two radio buttons (un/subscribe). I've tried the if statement, but I can't figure out what I'm doing wrong. Any help will be greatly appreciated!
Form:
<form action="newsletter.php" method="post" name="form">
<tr><td align=center colspan=2><font size=2><b>Free Newsletter</b></font></td></tr>
<tr><td>Name:</td><td><input type="text" name="name" size="24" maxlength="25" value=""></td></tr>
<tr><td>E-mail:</td><td><input type="text" name="email" size="24" maxlength="30" value=""></td></tr>
<tr><td colspan=2 align=center><input type="radio" name="choice" value="sub" checked>Subscribe <input type="radio" name="choice" value="unsub">Unsubscribe</td></tr>
<tr><td colspan=2 align=center><input type="submit" value="Submit"> </td></tr>
</form>
PHP:
<?
$name=$_POST['name'];
$email=$_POST['email'];
$to="leprakawn@hotmail.com";
$message="$name came to the site. E-mail: $email\n";
if ($choice == "sub") {$message = $message "Subscribed"; }
if ($choice == "unsub") {$message .= "Not Subscribed"; }
if(mail($to,"Newsletter Sub/Unsub",$message,"From: $email\n")) {
echo "Thank you for your interest. We will update our list depending on your choice.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
