Jump to content

Send and email form form


matt.sisto

Recommended Posts

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. 8)

Link to comment
https://forums.phpfreaks.com/topic/151604-send-and-email-form-form/
Share on other sites

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;
   }

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.