Jump to content

Recommended Posts

I have adapted the mail example from the php manual, but it must be wrong. If anyone can point out my mistakes I would really appreciate it. 8)

 

<?php

require "dbconn2.php";

  $email = $_POST['email'];
  $name = $_POST['name'];
  $body= $_POST['body'];
  $con_id =$_POST['con_id'];

  $sql = "SELECT email_address FROM consultant WHERE con_id = '$con_id'";
  $result=mysql_query($sql);
  
  $to      = $_GET['email_address'];
  $sender = $_GET['name'];
  $message = $_GET['body'];
  $from = $_GET['email'];

if (mail($to, $sender, $message, $from) {
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>
</html>

 

Which is it buddy? Post or get?  Since I do not know which, I will take it you meant POST and not GET

 

<?php
require "dbconn2.php";

if (isset($_POST['con_id'])) {
  $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);

/*  Redundant/not needed.
$sender = $name;
  $message = $_GET['body'];
  $from = $_GET['email'];*/

   if (mail($to, $sender, $message, $from) {
      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>
Error, no data was submitted.
</body>
</html>

 

Made some comments and removed/modified the code. Let me know of any questions about it.

Thanks Premiso and Ayon first of all for your help. Ayon before I added the mail script I was just echoing out the sql to make sure the right values were being passed from my form and I t worked so I am guessing it is just my mail script. Premiso I have tried what you suggested but it just returns a blank screen? do you have any further suggestions?

Does anybody have an idea as to why this code is not working and just displaying a blank page?

 

<?php
require "dbconn2.php";

if (isset($_POST['con_id'])) {
  $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);

/*  Redundant/not needed.
$sender = $name;
  $message = $_GET['body'];
  $from = $_GET['email'];*/

   if (mail($to, $sender, $message, $from) {
      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>
Error, no data was submitted.
</body>
</html>

 

appreciate any help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.