matt.sisto Posted March 31, 2009 Share Posted March 31, 2009 Hi. I now have my mail script working however as soon as I introduce an if statement it doesn't want to know? this is the working code: <?php require "dbconn2.php"; $from = $_POST['email']; $sender = $_POST['name']; $message = $_POST['body']; $con_id =$_POST['con_id']; $sql = "SELECT email_address FROM consultant WHERE con_id = '$con_id'"; $result=mysql_query($sql); $to = mysql_result($result, 0, 0); $headers = "From: $from"; mail($to, $sender, $message, $headers) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>?Message Consultant</title> </head> <body> </body> and with the if statement: <?php require "dbconn2.php"; $from = $_POST['email']; $sender = $_POST['name']; $message = $_POST['body']; $con_id =$_POST['con_id']; $sql = "SELECT email_address FROM consultant WHERE con_id = '$con_id'"; $result=mysql_query($sql); $to = mysql_result($result, 0, 0); $headers = "From: $from"; if mail($to, $sender, $message, $headers){ header("Location: message.php"); exit(); } else { header("Location: index.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>?Message Consultant</title> </head> <body> </body> Any ideas? Appreciate any help. Link to comment https://forums.phpfreaks.com/topic/151901-solved-mail-script-wont-work-with-an-if-statement/ Share on other sites More sharing options...
ScotDiddle Posted March 31, 2009 Share Posted March 31, 2009 matt.sisto, Have you tried this: ? <?php ... $success = mail($to, $sender, $message, $headers); if($success){ header("Location: message.php"); exit(); } else { header("Location: index.php"); exit(); } ?> Scot L. Diddle, Richmond VA Link to comment https://forums.phpfreaks.com/topic/151901-solved-mail-script-wont-work-with-an-if-statement/#findComment-797648 Share on other sites More sharing options...
matt.sisto Posted March 31, 2009 Author Share Posted March 31, 2009 Thanks. Link to comment https://forums.phpfreaks.com/topic/151901-solved-mail-script-wont-work-with-an-if-statement/#findComment-797656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.