matt.sisto Posted March 29, 2009 Share Posted March 29, 2009 Hi, I have built the form and I am now trying to get the php code to work, for some reason I can't get the messageconsultant.php script to work, can any one help. <?php require "dbconn2.php"; $sql="SELECT email_address, first_name, last_name FROM consultant"; $result=mysql_query($sql); $consultant_option=""; while ($row=mysql_fetch_array($result)) { $id=$row["first_name"]; $to=$row["email_address"]; $consultant_option.="<OPTION VALUE=\"$email_address\">".$id; } ?> <form name="messageConsultant" action="messageconsultant.php" method="post"> <label id="label1"> Your Email Address:</label> <input id="input1" type="text" name="email_address" value="<?=$row['email_address']?>"><p></p> <label id="label2">Your Name:</label><input id="input2" type="text" name="name" value="<?=$row['name']?>"> <label id="label3">Consultants Name:</label><select id="select1"><option value="<?=$row['consultant']?>">Choose <?=$consultant_option?> </option></select> <label id="label4">Message Content:</label><textarea id="input5" name="body" value="<?=$row['body']?>"></textarea> <input id="input6" type="submit" value="send" /> </form> messageconsultant.php <?php require "dbconn2.php"; $from = $_GET['email_address']; $to = $_GET['to']; $subject = $_GET['name']; $body = $_GET['body']; if (mail($to, $subject, $body, $from)) { header("Location: message.php"); exit(); } else { echo("<p>Message delivery failed...</p>"); } ?> <!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> </html> Appreciate any help. Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/ Share on other sites More sharing options...
revraz Posted March 29, 2009 Share Posted March 29, 2009 Your FROM Header is formatted incorrectly, you need the actual word FROM: in it. Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/#findComment-796229 Share on other sites More sharing options...
9three Posted March 29, 2009 Share Posted March 29, 2009 while ($row=mysql_fetch_array($result)) { $id=$row["first_name"]; $to=$row["email_address"]; $consultant_option.="<OPTION VALUE=\"$email_address\">".$id; } You did not define your variable email_address, yet you are using it. You are not echoing anything out, so you will not see the results even if everything is correct. It should be while ($row=mysql_fetch_array($result)) { $id=$row["first_name"]; $to=$row["email_address"]; $consultant_option.="<OPTION VALUE=\"$to\">".$id; echo $consultant_option; } Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/#findComment-796241 Share on other sites More sharing options...
chmpdog Posted March 29, 2009 Share Posted March 29, 2009 One line of code I recommend for you is: error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/#findComment-796247 Share on other sites More sharing options...
matt.sisto Posted March 29, 2009 Author Share Posted March 29, 2009 Ok thanks. Why isn't the messageconsultant.php script running, it just defaults to the the index? Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/#findComment-796256 Share on other sites More sharing options...
matt.sisto Posted March 29, 2009 Author Share Posted March 29, 2009 For some reason this just shows a blank page, can somebody help? <?php require "dbconn2.php"; $from = $_POST['email_address']; $to = $_POST['to']; $subject = $_POST['name']; $message = $_POST['body']; if mail($to, $subject, $message) { header("Location: message.php"); exit(); } else { header("Location: index.php"); exit(); } ?> Appreciate any help. Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/#findComment-796295 Share on other sites More sharing options...
revraz Posted March 29, 2009 Share Posted March 29, 2009 If you would enable error display and reporting, it would probably show you the error. Link to comment https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/#findComment-796351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.