Jump to content

[SOLVED] Mail script won't work with an if statement?


matt.sisto

Recommended Posts

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

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

 

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.