Jump to content

mailing html fromatted form results (arrays)


root.ryan

Recommended Posts

I have a form with a lot of information. I've managed to set the variable $body to the entire results page, almost. The only part I'm having a problem with is getting the array information (from a group of about 30 checkboxes) into a comma seperated string and assign a variable to it, so that I can include it with the rest of the info in $body to be sent via e-mail. I've tried a few different things unsuccessfully. Here's some code:

$body = "a whole lot of html here";print ("$body");  //this prints successfullyif ($mypost_100s[0] == "1")	{print ("<strong>All were checked.</strong>");} elseif ($mypost_100s == ""){print ("");} else {foreach ($mypost_100s as $areas100)	print ("$areas100, ");}print ("<font color=red>");if ($mypost_101op || $mypost_102op || $mypost_103op || $mypost_104op || $mypost_105op || $mypost_106op || $mypost_107op || $mypost_108op || $mypost_109op || $mypost_110op || $mypost_111op || $mypost_112op || $mypost_113op || $mypost_114op || $mypost_115op || $mypost_116op || $mypost_117op || $mypost_118op || $mypost_119op || $mypost_120op || $mypost_121op || $mypost_122op || $mypost_123op || $mypost_124op || $mypost_125op || $mypost_126op || $mypost_127op || $mypost_128op || $mypost_129op || $mypost_130op || $mypost_131op || $mypost_132op || $mypost_133op || $mypost_134op != ""){// this is special instruction stuff for 101s	print ("<BR>Special Instructions for 100s:<BR>");								if ($mypost_101op != "")			{			print ("101: $mypost_101op, ");			}		else			{			print ("");			}		if ($mypost_102op != "")			{			print ("102: $mypost_102op, ");			}		else//and it goes on like that

I would like all the information printed out in that to be included with the e-mail sent. (The first page, the actual form, has an area with chechboxes and textareas, where little comments can be put in with the checked item)Any help is appreciated.Thanks,Ryan

Link to comment
Share on other sites

You will want to use output buffering to create the page, save the output into a string, and then email the output to yourself.

ob_start; // start output buffering$body = "a whole lot of html here";print ("$body");  //this prints successfullyif ($mypost_100s[0] == "1")	{print ("<strong>All were checked.</strong>");} elseif ($mypost_100s == ""){print ("");} else {foreach ($mypost_100s as $areas100)	print ("$areas100, ");}print ("<font color=red>");if ($mypost_101op || $mypost_102op || $mypost_103op || $mypost_104op || $mypost_105op || $mypost_106op || $mypost_107op || $mypost_108op || $mypost_109op || $mypost_110op || $mypost_111op || $mypost_112op || $mypost_113op || $mypost_114op || $mypost_115op || $mypost_116op || $mypost_117op || $mypost_118op || $mypost_119op || $mypost_120op || $mypost_121op || $mypost_122op || $mypost_123op || $mypost_124op || $mypost_125op || $mypost_126op || $mypost_127op || $mypost_128op || $mypost_129op || $mypost_130op || $mypost_131op || $mypost_132op || $mypost_133op || $mypost_134op != ""){// this is special instruction stuff for 101s	print ("<BR>Special Instructions for 100s:<BR>");								if ($mypost_101op != "")			{			print ("101: $mypost_101op, ");			}		else			{			print ("");			}		if ($mypost_102op != "")			{			print ("102: $mypost_102op, ");			}		else//and it goes on like that//once the entire page has been generated, get it all in a string$output = ob_get_contents(); //save the contentsob_end_clean(); //delete the buffer and end output buffering// build the HTML email, from php.net$to = 'xxx@example.com';// subject$subject = 'results';// To send HTML mail, the Content-type header must be set$headers  = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";// Additional headers$headers .= 'From: The Internet <xyz@example.com>' . "\r\n";// Mail itmail($to, $subject, $output, $headers);print "Mail sent";

More on mail:http://www.php.net/manual/en/function.mail.phpYou can also replace these:$output = ob_get_contents(); //save the contentsob_end_clean(); //delete the buffer and end output bufferingwith this:$output = ob_get_clean();But I left the first two in there for clarity.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...