Jump to content

Recommended Posts

Hello!

 

I have the following php code:

 

<?php
// The message
$message =
"[request("Id_From")]\n
[request("ID")]\n
[request("CUT")]\n
[request("MAKE")]\n
[request("CARAT")]\n
[request("PRICE_PC")]\n
[request("CLARITY")]\n
[request("LOCATION")]\n
[request("CERTIFICATE")]\n
[request("SUP_STOCK_REF")]\n
[request("Measurements")]\n
[request("Total_Depth")]\n
[request("Polish")]\n
[request("Table_Width")]\n
[request("Symmetry")]\n
[request("Crown_Height")]\n
[request("Culet")]\n
[request("Parillion_Depth")]\n
[request("Graining")]\n
[request("Girdle")]\n
[request("Remarks")]\n
[request("TotalPrice")]";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail('gary.impact@gmail.com', 'HIGH PRIORITY DIAMOND ORDER!', $message);
?>

 

where I am trying to send an email to myself which will send me the listed 'requested' values.  These values are to the script in the form of:

 

http://www.somedomain.com/somepage.html?Id_From=123&ID=50250430&CUT=Round&MAKE=VG+-+G++++&CARAT=.5&PRICE_PC=5719&COLOR=D&CLARITY=VVS1&LOCATION=California+%28U.S.A.%29&CERTIFICATE=GIA&SUP_STOCK_REF=3540-6&Measurements=5.03x5.08x3.17&Total_Depth=62.7%25&Polish=V.good&Table_Width=60%25&Symmetry=Good&Crown_Height=&Culet=None&Parillion_Depth=&Graining=&Girdle=&Fluorescence=None&Remarks=&TotalPrice=2860

 

I am getting the error:

 

Parse error: syntax error, unexpected T_STRING

 

Which starts on the first line of my requested data ("[request("Id_From")]\n).

 

Any help on this would be truely appreciated!

 

Thank you!

in case the following will work for you, make sure you read something about preventing email header injection. because this script is allows it.

 

try instead of request the following notation.

$message = "
  $_GET['Id_From'];
  //etc

";

 

and again don't forget to read about email header injection

I tried just putting one line on like this:

 

<?php
// The message
$message =
$_GET['TotalPrice'];

 

and it works fine.

 

If I add one more line like this:

 

<?php
// The message
$message =
$_GET['TotalPrice'];
$_GET['CARAT'];

 

It still ONLY prints the first line?  If I enclose it in anything (', ", (), etc) like:

 

<?php
// The message
$message ="[/color]
$_GET['TotalPrice'];
$_GET['CARAT'];"[/color]

 

it gives me an error

yes that's because your closing the line with the semicolon.

also something to read about is the concatenating dot.

http://php.net/manual/en/language.operators.string.php  :idea:

 

try:

$message = 
$_GET['TotalPrice']. // notice the little dot
$_GET['CARAT']

;//end with a semicolon.

 

if you are going to put standard text in between the variables you need to use " " around it of course. when in doubt check the manual :)

When validating or processing a number of forms fields, it is usually a good idea to have an array of the expected from field names (and labels). You can also use this array to produce the form using php code instead of hard-coding it.

 

This would let you loop through the expected field names (lets you ignore any fields not part of your form that a spammer has submitted) and form a message dynamically, rather then hard-code each line in the message. If you need to add/subtract any form fields, you would simply alter the array that is defining the list of fields.

<?php

$fields = array();
$fields["Id_From"] = "some label to use with this field...";
$fields["ID"] = "some label to use with this field...";
$fields["CUT"] = "some label to use with this field...";
$fields["MAKE"] = "some label to use with this field...";
$fields["CARAT"] = "some label to use with this field...";
$fields["PRICE_PC"] = "some label to use with this field...";
$fields["CLARITY"] = "some label to use with this field...";
$fields["LOCATION"] = "some label to use with this field...";
$fields["CERTIFICATE"] = "some label to use with this field...";
$fields["SUP_STOCK_REF"] = "some label to use with this field...";
$fields["Measurements"] = "some label to use with this field...";
$fields["Total_Depth"] = "some label to use with this field...";
$fields["Polish"] = "some label to use with this field...";
$fields["Table_Width"] = "some label to use with this field...";
$fields["Symmetry"] = "some label to use with this field...";
$fields["Crown_Height"] = "some label to use with this field...";
$fields["Culet"] = "some label to use with this field...";
$fields["Parillion_Depth"] = "some label to use with this field...";
$fields["Graining"] = "some label to use with this field...";
$fields["Girdle"] = "some label to use with this field...";
$fields["Remarks"] = "some label to use with this field...";
$fields["TotalPrice"] = "some label to use with this field...";

// form processing code, detect if the first (expected) get parameter is present
if(isset($_GET["Id_From"])){
$errors = array(); // array to hold any validation errors

// validate all the expected data here ...	

// process the data if no validation errors 
if(empty($errors)){
	// loop over the expected fields and form the mail message
	$message = ''; // define variable/empty message
	foreach($fields as $key => $label){
		$message .= "$label: $_GET[$key]\n";
	}
	$message = wordwrap($message, 70);
	if(mail('gary.impact@gmail.com', 'HIGH PRIORITY DIAMOND ORDER!', $message)){
		echo "Sending Mail server accepted the email to send!";
	} else {
		echo "Sending Main server rejected the email!";
	}
}
}
?>

Once you have an array that defines the form fields and labels, you can dynamically produce and output the form like so -

 

	$form = "<form method='get' action=''>\n";
foreach($fields as $key => $label){
	$form .= "<label for='$key'>$label:</label>\n<input type='text' id='$key' name='$key' value=''><br />\n";
}
$form .= "<input type='submit'>\n</form>";
echo $form;

Thank you!

 

How can the list of fields be printed along with "echo "Sending Main server rejected the email!";"  line?  I may like to put text before and after the 'list of fields'.  My final objective will be to have all this information print to my customers web page with the option to print as well as email me a copy (which we have already accomplished).

 

Thanks!

Thank you!

 

Your code above returns text boxes instead of my extracted values (which are sent to the emails):

 

	$form = "<form method='get' action=''>\n";
foreach($fields as $key => $label){
	$form .= "<label for='$key'>$label:</label>\n<input type='text' id='$key' name='$key' value=''><br />\n";
}
$form .= "<input type='submit'>\n</form>";
echo $form;

 

What I would like to do is give the customer confirmation of his request.  I have tried the following with various formats (see first "echo" area for changes):

 

<?php

$fields = array();
$fields["Id_From"] = "ID_From:";
$fields["ID"] = "ID:";
$fields["CUT"] = "Cut:";
$fields["MAKE"] = "Make:";
$fields["CARAT"] = "Carats:";
$fields["PRICE_PC"] = "Price per carat:";
$fields["CLARITY"] = "Clarity:";
$fields["LOCATION"] = "Location:";
$fields["CERTIFICATE"] = "Certificate:";
$fields["SUP_STOCK_REF"] = "Sup Stock Ref:";
$fields["Measurements"] = "Measurments:";
$fields["Total_Depth"] = "Total Depth";
$fields["Polish"] = "Polish:";
$fields["Table_Width"] = "Table Width:";
$fields["Symmetry"] = "Symmetry:";
$fields["Crown_Height"] = "Crown Height:";
$fields["Culet"] = "Culet:";
$fields["Parillion_Depth"] = "Parillion Depth:";
$fields["Graining"] = "Graining:";
$fields["Girdle"] = "Girdle:";
$fields["Remarks"] = "Remarks:";
$fields["TotalPrice"] = "Total Price:";

// form processing code, detect if the first (expected) get parameter is present
if(isset($_GET["Id_From"])){
$errors = array(); // array to hold any validation errors

// validate all the expected data here ...

// process the data if no validation errors
if(empty($errors)){
	// loop over the expected fields and form the mail message
	$message = ''; // define variable/empty message
	foreach($fields as $key => $label){
		$message .= "$label: $_GET[$key]\n";
	}
	$message = wordwrap($message, 70);
	if(mail('gary.impact@gmail.com', 'HIGH PRIORITY DIAMOND ORDER/INQUIRY!', $message)){
	echo
	$message = ''; // define variable/empty message
	foreach($fields as $key => $label){
		$message .= "$label: $_GET[$key]\n";
	}
echo $message;
		echo "Thank you for your interest in our products!  Your loose diamond order will be validated and checked for errors.  We should be back with you within 24 to 48 hours at which time we will need to accept payment and process your order.  Thank you!";
	} else {
		echo "Sending Main server rejected the email!";
	}
}
}
?>

 

but I am obviously doing something wrong in the syntax since the list prints in the customers view but the line breaks (\n) are ignored?  I first just put in the "echo $message;" line and got same results.  That is why I tried re-entering the code above it to try to get the formatting I wanted.  Can you tell me what I am doing wrong?

 

Thank you!

OK, got it!  Area right after email line added.  I figured this out by modifying 'PFMaBiSmAd's' last code!

 

<?php

$fields = array();
$fields["Id_From"] = "ID_From:";
$fields["ID"] = "ID:";
$fields["CUT"] = "Cut:";
$fields["MAKE"] = "Make:";
$fields["CARAT"] = "Carats:";
$fields["PRICE_PC"] = "Price per carat:";
$fields["CLARITY"] = "Clarity:";
$fields["LOCATION"] = "Location:";
$fields["CERTIFICATE"] = "Certificate:";
$fields["SUP_STOCK_REF"] = "Sup Stock Ref:";
$fields["Measurements"] = "Measurments:";
$fields["Total_Depth"] = "Total Depth";
$fields["Polish"] = "Polish:";
$fields["Table_Width"] = "Table Width:";
$fields["Symmetry"] = "Symmetry:";
$fields["Crown_Height"] = "Crown Height:";
$fields["Culet"] = "Culet:";
$fields["Parillion_Depth"] = "Parillion Depth:";
$fields["Graining"] = "Graining:";
$fields["Girdle"] = "Girdle:";
$fields["Remarks"] = "Remarks:";
$fields["TotalPrice"] = "Total Price:";

// form processing code, detect if the first (expected) get parameter is present
if(isset($_GET["Id_From"])){
$errors = array(); // array to hold any validation errors

// validate all the expected data here ...

// process the data if no validation errors
if(empty($errors)){
	// loop over the expected fields and form the mail message
	$message = ''; // define variable/empty message
	foreach($fields as $key => $label){
		$message .= "$label: $_GET[$key]\n";
	}
	$message = wordwrap($message, 70);
	if(mail('gary.impact@gmail.com', 'HIGH PRIORITY DIAMOND ORDER/INQUIRY!', $message)){

		echo 'Additional test text here!'; // Text before diamond data here.
		echo "<br />";
		echo "<br />";
			foreach($fields as $key => $label){
				$message2 .= "<label for='$key'>$label:$_GET[$key]<br />\n";
			}
		echo $message2;
		echo "<br />";
		echo "Thank you for your interest in our products!  Your loose diamond order will be validated and checked for errors.  We should be back with you within 24 to 48 hours at which time we will need to accept payment and process your order.  Thank you!"; //Text after diamond data here.
	} else {
		echo "Sending Main server rejected the email!";
	}
}
}
?>

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.