chrispulliam Posted March 21, 2012 Share Posted March 21, 2012 I am having issues with my page. I am trying to send a email to a different address based on the entry that my user submits. Here is my form on my test page. <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>Test</b></td> <td><input type=text name=test size=25></td> <td> </td> <td> </td> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=FA value=SendMail> </p> <input type=submit value="Submit Form"> </p> </div> </form> here is the php code for my formdata page <?php $con = mysql_connect("localhost","test","test"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $sql="INSERT INTO formdata (test) VALUES ('$_POST[test]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); if ($_POST['test'] =="A"){ $to = "email@sample.com"; $subject = "Custom Form"; $message = $_POST['test'] ; $headers = "From: email@sample.com"; $sent = mail($to, $subject, $message, $headers) ; } else if ($_POST['test'] =="B"){ $to = "email2@sample.com"; $subject = "Custom Form"; $message = $_POST['test'] ; $headers = "From: email@sample.com"; $sent = mail($to, $subject, $message, $headers) ; } if($sent) {print "<p>Your mail was sent successfully"; } else {print "<p>We encountered an error sending your mail"; } ?> Quote Link to comment Share on other sites More sharing options...
smerny Posted March 21, 2012 Share Posted March 21, 2012 you should say what issue you are having rather than making us guess Quote Link to comment Share on other sites More sharing options...
chrispulliam Posted March 21, 2012 Author Share Posted March 21, 2012 Sorry forgot to add I am having issues getting the email to work. Regardless of the Text in the form it goes to the first email address listed with all submissions. Quote Link to comment Share on other sites More sharing options...
smerny Posted March 21, 2012 Share Posted March 21, 2012 so ($_POST['test'] == "A") is always true? Quote Link to comment Share on other sites More sharing options...
chrispulliam Posted March 21, 2012 Author Share Posted March 21, 2012 I just noticed the issue! if ($_POST['test'] == "A"){ had a extra space in it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.