0

following is my script for send email inquiry.. the recipient email address was stored in a db called users.. this script will not work properly.. i think the problem is recipient email section.. because when i used a email address instead of $user it will work..

thanx help me

<?php
$refno = $HTTP_POST_VARS['refno'];
$proid = $HTTP_POST_VARS['proid'];
$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$msg = $HTTP_POST_VARS['msg'];

//connect db and find email address related to id
include 'db_connector.php';
$id=$HTTP_POST_VARS['id'];
$query=mysql_query("SELECT user_email FROM users WHERE id='".$id."'");
$cont=mysql_fetch_array($query);
$user=$cont['user_email'];  

// recipient name
$recipientname = "'".$name."'";

// recipient email
$recipientemail = $user ;


// subject of the email sent to you
$subject = "Inquiry for your advertisement No. (".$refno.")";

// send an autoresponse to the user?
$autoresponse = "no";

// subject of autoresponse
$autosubject = "Thank you for your inquiry!";

// autoresponse message
$automessage = "Thank you for your inquiry.! We'll get back to you shortly.

";

// END OF NECESSARY MODIFICATIONS


$message = "reference number : $refno

$msg

From $name $email 

---"; 


// send mail and print success message
mail($recipientemail,"$subject","$message","From: $recipientname <$email>");

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}

header("Location:index.php");
exit;

?>
1
  • Check if you the email address you get from the query is proper. Commented Jun 16, 2011 at 11:07

3 Answers 3

1

First of all, your query is SQL injectable. Never ever pass a variable coming from a POST request directly into an SQL query. Use mysql_real_escape().

As to your bug: it seems that $user does not contain a valid e-mail address. so, the Mysql query is not returning an e-mail address.

Use $_POST rather than $HTTP_POST_VARS.

Switch on error reporting by prepending these two lines to your PHP code:

PHP code:

error_reporting(E_ALL);
ini_set('display_errors','1');

Run your script again. Do you get any notices or warnings?

If not, try to display your query, by adding

die($query);

just before the line that has the mysql_query command, and then run the query manually (e.g. using PhpMyAdmin or MySQL Query Browser) to see if you are actually getting a result that looks like an e-mail address.

Sign up to request clarification or add additional context in comments.

2 Comments

i changed to $_POST, also i add the error code now there is error on $id=$_POST['id']; line, and there is a valid email id available in the table error is Notice: Undefined index: id in /sendinq.php on line 14
Is line 14 the line in which $_POST['id'] is referenced? In that case: are you sure you actually have a POST variable called 'id' in your request?
0

Debug your PHP program.

Check out :

  • If the variables contain the supposed values.
  • Query is okay and returns result.
  • Proper header is set with mail function.
  • etc.

PHP manual have a good example to send mail.

Do not use $HTTP_POST_VARS['name']; it is deprecated use $_POST instead.

Comments

0

hey guys thanx for the help.. i found the error done in my inquiry form.. the id filed hidden outside of the form tag.. therefore the id value will not passed to the sendinq.php. i change it thank now the sendmail option work properly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.