Jump to content

POSTing name from Database into the Greeting of email letter?


lazerbrains

Recommended Posts

I have an email form that is working wonderfully. I have a select box that has a list of names of people that you can email. That list is being pulled from a database.

 

It is currently sending to the email related to the name selected in the dropdown menu. However, in the email that sends, I would like the name of the recipient to show up in the greeting. I.E. Dear "name from dropdown".

 

How do I go about doing this. My select box that holds the query for the name is as folows:

 

<?php 
echo '<select name="First_and_Last_Name">';
while( $array = mysql_fetch_assoc($result) ) {
    $text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"];
$value_for_select = $array["Email"];
echo "<option></option>\n";
echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; 
}
echo '</select>';?> 

 

No, this is querying the First and Last Name and another variable called district in to a new variable called "text_for_select". I just want to either print the "text_for_select" after the "Dear", or better yet, just the "First_Name" and "Last_Name".

 

How would I get this to print there?

Link to comment
Share on other sites

Ok so I had a bit of a play around, and my next question would be, are you sure you've put the values into the array correctly?

 

I checked online, and found out to input the values, and then I simply echoed out one value at a time, and it worked fine, which means it will print into your email fine..

 

For testing, I would try echoing just First Name, and then just Last Name, separately, and see if it prints anything. This way you can see if the data is going into the array fine. If the values print as expected, then the string you'r building for the email is being built incorrectly.

 

Here is the code I made, which worked perfectly fine.

$arr = array("FirstName" => "John", "LastName" => "Doe", "Age" => "23");
echo $arr["FirstName"];
echo "\n";
echo $arr["LastName"];
echo "\n";
echo $arr["Age"];

Link to comment
Share on other sites

Well the array is already pulling the correct values from the database. I is pulling them in the Form:

 

<form method="post" action="" id="letter">
<p><label for="date">Date</label>
<input type="text" name="date" id="date" value="<?php echo $_POST['date'];?>"/></p>
<p>Dear Person,
<?php 
echo '<select name="First_and_Last_Name">';
while( $array = mysql_fetch_assoc($result) ) {
$text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"];
$value_for_select = $array["Email"];
echo "<option></option>\n";
echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; 
}
echo '</select>';?>

</p>

 

That is currently pulling the First Name and Last name into a drop down menu. It is working fine. I just want to pull the name of the person selected into the Greeting of the email. SO that it says "Dear 'Name from $text_for_select'.

 

Isn't there a better way to do that?

 

Link to comment
Share on other sites

I did that. Added into this:

 

<?php 



if($_POST){

$to = $_POST['First_and_Last_Name'];
$subject = "WHAT SHOULD THIS BE";	
$message  =  "Date: $date\n\r".
			 echo "Dear ";
echo "$array["First_Name"];
echo " ";  //space
echo "$array["Last_Name"];
			"" .$_POST['comment']. "\n\r".
			"Sincerely,\n".
			"From: " .$_POST['from']. "\n". 
			"Street: " .$_POST['street']. "\n".
			"City: " .$_POST['city']. "\n".
			"Zip: " .$_POST['zip']. "\n".
			"Email: " .$_POST['email']. "\n".
$headers = "From: " .$_POST['from']. "<".$_POST['email'].">"."\n";
mail($to, $subject, $message, $headers);
// SUCCESS!
echo '<p class="notice">'.
	'Thank you for your submission.  '.
 	 '</p>';
// clear out the variables for good-housekeeping
unset($date,$bill,$name,$street,$city,$zip,$email);
$_POST = array();
}
?>

 

and got this:

 

Parse error: syntax error, unexpected T_ECHO in /home5/windfal2/public_html/ledge/wp-content/themes/arras/letter.php on line 31

 

Still sent when the code was this:

 

<?php 



if($_POST){

$to = $_POST['First_and_Last_Name'];
$subject = "WHAT SHOULD THIS BE";	
$message  =  "Date: $date\n\r".
			 "Dear " . $array["First_Name"] . " " . $array["Last_Name"]. ",\n\r".
			"" .$_POST['comment']. "\n\r".
			"Sincerely,\n".
			"From: " .$_POST['from']. "\n". 
			"Street: " .$_POST['street']. "\n".
			"City: " .$_POST['city']. "\n".
			"Zip: " .$_POST['zip']. "\n".
			"Email: " .$_POST['email']. "\n".
$headers = "From: " .$_POST['from']. "<".$_POST['email'].">"."\n";
mail($to, $subject, $message, $headers);
// SUCCESS!
echo '<p class="notice">'.
	'Thank you for your submission.  '.
 	 '</p>';
// clear out the variables for good-housekeeping
unset($date,$bill,$name,$street,$city,$zip,$email);
$_POST = array();
}
?>

Link to comment
Share on other sites

<?php 



if($_POST){

$to = $_POST['First_and_Last_Name'];
$subject = "WHAT SHOULD THIS BE";	
$message  =  "Date: $date\n\r".
LINE 31		 echo "Dear ";
echo "$array["First_Name"];
echo " ";  //space
echo "$array["Last_Name"];
			"" .$_POST['comment']. "\n\r".
			"Sincerely,\n".
			"From: " .$_POST['from']. "\n". 
			"Street: " .$_POST['street']. "\n".
			"City: " .$_POST['city']. "\n".
			"Zip: " .$_POST['zip']. "\n".
			"Email: " .$_POST['email']. "\n".
$headers = "From: " .$_POST['from']. "<".$_POST['email'].">"."\n";
mail($to, $subject, $message, $headers);
// SUCCESS!
echo '<p class="notice">'.
	'Thank you for your submission.  '.
 	 '</p>';
// clear out the variables for good-housekeeping
unset($date,$bill,$name,$street,$city,$zip,$email);
$_POST = array();
}
?>

Link to comment
Share on other sites

Nevermind, I copied it into Dreamweaver and fixed the problem:

if($_POST){

$to = $_POST['First_and_Last_Name'];
$subject = "WHAT SHOULD THIS BE";	
$message  =  "Date: $date\n\r";
			 echo "Dear ";

echo $array["First_Name"];
echo " ";
echo $array["Last_Name"];
			"" .$_POST['comment']. "\n\r".
			"Sincerely,\n".
			"From: " .$_POST['from']. "\n". 
			"Street: " .$_POST['street']. "\n".
			"City: " .$_POST['city']. "\n".
			"Zip: " .$_POST['zip']. "\n".
			"Email: " .$_POST['email']. "\n".
$headers = "From: " .$_POST['from']. "<".$_POST['email'].">"."\n";
mail($to, $subject, $message, $headers);
// SUCCESS!
echo '<p class="notice">'.
	'Thank you for your submission.  '.
 	 '</p>';
// clear out the variables for good-housekeeping
unset($date,$bill,$name,$street,$city,$zip,$email);
$_POST = array();
}

 

I got my quotes wrong :D, sorry lol.

 

Denno

Link to comment
Share on other sites

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.