Jump to content

MAIL script not working, any help appreciated.


matt.sisto

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.

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.