What is wrong with my php process mail form?

xynapse

Limp Gawd
Joined
Nov 15, 2005
Messages
142
I have been trying to figure this out for some time now. I think I'm making it harder than it's supposed to be. For some reason it's not passing values to my email but I do get an email.


Code:
<?php
include("connection.php");

	
$SQL = "SELECT * FROM product_offer WHERE id = ".$_REQUEST['id']."";
			$exe = mysql_query($SQL);
			$row = mysql_fetch_array ($exe);
?>


<?php     	 
					 $SELect = "SELECT * FROM product_offer ORDER BY id DESC LIMIT 1";
					 $Query_exe = mysql_query($SELect);	 
					if($PRO_id = mysql_fetch_array($Query_exe)) { 
					?>
					
<?php	
        $customer_price = $_POST['customer_price'];
	$email = $_POST['email'];
	$client_name = $_POST['client_name'];
	$contact_number = $_POST['contact_number'];					
        $toEmail = "[email protected]";
        $subject = "Junk Car ";
        $message = "Thank you for accepting our offer";
        $body = "
----------------------------------------------------------------------------- 
   WEBSITE CONTACT ENQUIRY
----------------------------------------------------------------------------- 
Customer Price : $customer_price
Email : $email
Name : $client_name
Contact Number : $contact_number
Message = $message
____________________________________ 
End of Email 
";
$topHeader = "From: $email\n";
$topHeader . "MIME-Version: 1.0\n"
		   . "Content-Transfer-Encoding: 7bit\n"
		   . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";

 if(mail($toEmail,$subject, $body, $topHeader))
     {
     echo "<center><b>Congratulation, you have successfully submitted your information. We will Contact you within 24 Hours.  <br /> You will be redirected shortly or click on following link. <a href='index.html'> Home </a> <b></center>";
     }
?> 
<?php
					$thanks = "Thank you for submission";					
					}
					
					?>
 
There are no errors. I'm just not getting any values for $customer_price or anything else in the email.
 
Post your form code. The ids/names of the fields might not match to what you have in the variable setup portion of your code.
 
Last edited:
Post your form code. The ids/names of the fields might not match to what you have in the variable setup portion of your code.

I don't think it's empty. Did I do it wrong? Here is $body

Code:
$body = "
----------------------------------------------------------------------------- 
   WEBSITE CONTACT ENQUIRY
----------------------------------------------------------------------------- 
Customer Price : $customer_price
Email : $email
Name : $client_name
Contact Number : $contact_number
Message = $message
____________________________________ 
End of Email 
";
 
Post your form code. The ids/names of the fields might not match to what you have in the variable setup portion of your code.

Here is the previous page that calculates a value and goes to the process script. Everything here works fine.

Code:
<?php	 	
include("connection.php");
	$car_id = $_POST['pro_id'];
	$year = $_POST['year'];
	$make = $_POST['make'];
	$model = $_POST['model'];
	$vehicle_paidoff = $_POST['vehicle_paidoff'];
	$title = $_POST['title'];
	$amount = $_POST['amount'];
	$select_one = $_POST['select_one'];
	$vehicle_complete = $_POST['vehicle_complete'];
	$drivable = $_POST['drivable'];
	$body_part = $_POST['body_part'];
	$interior_component = $_POST['interior_component'];
	$vehicle_fire = $_POST['vehicle_fire'];	
	$email = $_POST['email'];
	$client_name = $_POST['client_name'];
	$contact_number = $_POST['contact_number'];
	
	
	$sql = "SELECT * FROM car where pro_id = ". $car_id;
	$execute = mysql_query($sql);
	$row = mysql_fetch_array($execute);

	$vehicle_price =  $row['initial_price'];
	
	$ratio_sql = "SELECT * FROM ratio";
	$ratio_execute = mysql_query($ratio_sql);
	$ratio_row = mysql_fetch_array($ratio_execute);
	
	$metal_ratio = $ratio_row['weight'];
		
	if($title == "no") {
		$vehicle_price = $vehicle_price - 1000;
	}
	if($vehicle_complete == "no") {
			$vehicle_price = $vehicle_price - 1000;
	}
	if($body_part == "no") {
		
			$vehicle_price = $vehicle_price - 400;
	}
	if($interior_component == "no") {
		$vehicle_price = $vehicle_price - 350;
	}
	if($vehicle_fire == "yes") {
			$vehicle_price = $vehicle_price - 1000;
		}
		$vehicle_price = $vehicle_price * $metal_ratio;
	
	$update = "UPDATE product_offer SET
				email = '".$email."',
				offer_price = '".$vehicle_price."',
				client_name = '".$client_name."',
				contact_number = '".$contact_number."' 
				WHERE id = ".$_POST['id']."";
				
				$exe = mysql_query($update);
				if($exe) {
	 $message1 =  "<h1 align='center'>Your Offer is $".$vehicle_price."</h1>";
	 				
				}
?>






<h2><?php	 	 echo $message1; ?></h2>
                   <?php     	 
					 $SQL = "SELECT * FROM product_offer ORDER BY id DESC LIMIT 1";
					 $DECline_query = mysql_query($SQL); 
					while($PRO_id = mysql_fetch_array($DECline_query)) { 
					?>
                    <div id="accept"> 	
                    <a class="button" href="process.php?id=<?php echo $PRO_id['id'] ?>">Accept</a>
 
Hard to tell without seeing the actual form you are submitting. Also this is vulnerable to SQL injection.
 
Looks like I'm going to have to further redesign the site. It's hard to explain. lol I was trying to eliminate a scheduling page and just get it to process an email with the selected info. Thanks for helping.
 
Yeah, when we say the form we mean the actual HTML code that's rendering the form.

You're doing this: $foo = $_POST['customer_price']

If the HTML textbox for the customer price is labeled something other than customer_price then $foo will be empty.
 
I finally got something to work. I thought about it and thought about it trying to keep it simple. I don't even need a processing page. I just wanted it to send an email if the person accepted the offer or not.

Here is what I did.

In the top of the page I defined my mail variables.

Code:
$email = $_POST['email'];
	$client_name = $_POST['client_name'];
	$contact_number = $_POST['contact_number'];
	$to = "[email protected]";
        $subject = "Test";
	$message = "$car_id $year $make $model $vehicle_paidoff $title $amount                       $select_one $vehicle_complete $drivable" ;
	$from = $email;
	$headers = "From:" . $from;

Then in the bottom button for accept the offer I call the mail function. Now I can include any variable I want in the email. Works like a charm! :D

Code:
<a class="button" href="accept_offer.php?id=<?php mail($to,$subject,$message,$headers); echo $PRO_id['id'] ?>">Accept</a>

Here is the whole page.

Code:
<?php	 	
include("connection.php");
	$car_id = $_POST['pro_id'];
	$year = $_POST['year'];
	$make = $_POST['make'];
	$model = $_POST['model'];
	$vehicle_paidoff = $_POST['vehicle_paidoff'];
	$title = $_POST['title'];
	$amount = $_POST['amount'];
	$select_one = $_POST['select_one'];
	$vehicle_complete = $_POST['vehicle_complete'];
	$drivable = $_POST['drivable'];
	$body_part = $_POST['body_part'];
	$interior_component = $_POST['interior_component'];
	$vehicle_fire = $_POST['vehicle_fire'];	
	$email = $_POST['email'];
	$client_name = $_POST['client_name'];
	$contact_number = $_POST['contact_number'];
	$to = "[email protected]";
                $subject = "Test";
				$message = "$car_id $year $make $model $vehicle_paidoff $title $amount $select_one $vehicle_complete $drivable" ;
				$from = $email;
				$headers = "From:" . $from;
	
	$sql = "SELECT * FROM car where pro_id = ". $car_id;
	$execute = mysql_query($sql);
	$row = mysql_fetch_array($execute);

	$vehicle_price =  $row['initial_price'];
	
	$ratio_sql = "SELECT * FROM ratio";
	$ratio_execute = mysql_query($ratio_sql);
	$ratio_row = mysql_fetch_array($ratio_execute);
	
	$metal_ratio = $ratio_row['weight'];
		
	if($title == "no") {
		$vehicle_price = $vehicle_price - 1000;
	}
	if($vehicle_complete == "no") {
			$vehicle_price = $vehicle_price - 1000;
	}
	if($body_part == "no") {
		
			$vehicle_price = $vehicle_price - 400;
	}
	if($interior_component == "no") {
		$vehicle_price = $vehicle_price - 350;
	}
	if($vehicle_fire == "yes") {
			$vehicle_price = $vehicle_price - 1000;
		}
		$vehicle_price = $vehicle_price * $metal_ratio;
	
	$update = "UPDATE product_offer SET
				email = '".$email."',
				offer_price = '".$vehicle_price."',
				client_name = '".$client_name."',
				contact_number = '".$contact_number."' 
				WHERE id = ".$_POST['id']."";
				
				$exe = mysql_query($update);
				if($exe) {
	 $message1 =  "<h1 align='center'>Your Offer is $".$vehicle_price."</h1>";
	 			
				
	 
				}
?>
<!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=iso-8859-1" />
<title>Thank You</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
	<div id="main">
    	<div id="wrapper" class="float_left">
        	<div id="header" class="float_left">
            	<div id="logo" class="float_left">
                	<img src="images/logo.png" width="238" height="56" alt="logo" />
                </div>
                <!-- -->
                	<?php	 	 include("menu.php"); ?>
                
                <!-- -->
            </div>
            <div id="content_area" class="float_left">
            	<div id="top_content_area" class="float_left">
                	<div id="top_left" class="float_left">
                    
                    </div>
                </div>
                <div id="bottom_content_area" class="float_left">
                	<div id="bottom_left" class="float_left">
                    <h2><?php	 	 echo $message1; ?></h2>
                   <?php     	 
					 $SQL = "SELECT * FROM product_offer ORDER BY id DESC LIMIT 1";
					 $DECline_query = mysql_query($SQL); 
					while($PRO_id = mysql_fetch_array($DECline_query)) { 
					?>
                    <div id="accept"> 	
                    <a class="button" href="accept_offer.php?id=<?php mail($to,$subject,$message,$headers); echo $PRO_id['id'] ?>">Accept</a>  &nbsp;&nbsp;&nbsp;
                    <a class="button" href="customer_price.php?id=<?php echo $PRO_id['id'] ?>">Decline</a>
                    </div>
                                      
                  

                    
					<?php }?>
                        <div class="content_field float_left">
                        	
                        </div>
                        
                    </div>
                    <div id="bottom_right" class="float_left">
                    
                    </div>
                </div>
            </div>
            <!-- Footer Start -->
            <?php	 	
				include("footer.php");
			?>
        </div>
    </div>
</body>
</html>
 
Even though that "works" it is broken in the sense that it does far more than you intend it to. I'd suggest following the example that is marked as correct here. Personally I use the mysqli method.
 
Here is the problem:
PHP:
$topHeader = "From: $email\n";
$topHeader . "MIME-Version: 1.0\n"
		   . "Content-Transfer-Encoding: 7bit\n"
		   . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";

Notice
$topHeader . "MIME-Version: 1.0\n"

Try using:

PHP:
$topHeader = "From: $email\n";
$topHeader .= "MIME-Version: 1.0\n"
		   . "Content-Transfer-Encoding: 7bit\n"
		   . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";
 
Back
Top