[PHP] Looking for easier way to build email message
Drew a blank off the archive, so here goes... I'm working on some forms for our company website, all of which simply have to be mailed to us by email. After verifying that the content of all the fields is valid and the proper type, it builds the email message as following. This all works great, but I want a simpler/easier way to reuse the code (we have 3 forms, with distinctively different content, but the mail process remains the same), so something that will do the below, but can be reduced to something like grabbing a text file and fill in the blanks would be nice, instead of this: // prepare message if(! $error) { $message = Information submitted with Tee Time booking form:\r\n; $message .= Name and address:\r\n\r\n; $message .= $name\r\n; $message .= $address\r\n; $message .= $city\r\n; $message .= $state $postcode\r\n\r\n; $message .= Email: $email\r\n; $message .= Phone: $phone\r\n; $message .= \r\n\r\nBooking info:\r\n\r\n; $message .= Arrival: $a_month $a_day\r\n; $message .= Departure: $d_month $d_day\r\n; $message .= Persons: $persons\r\n; $message .= Rooms: $rooms\r\n; $message .= \r\nGolf Courses\r\n\r\n; for($i = 1; $i 8; $i++) { if($_POST['course_'.$i] != 0) { $message .= 'Course: '.$_POST['course_'.$i].\r\n; $message .= 'Date: '.$_POST['month_'.$i].' '.$_POST['day_'.$i].\r\n; $message .= 'Time: '.$_POST['teetime_'.$i].\r\n; $message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n; } } if(! empty($comments)) { $message .= \r\nComments:\r\n$comments\r\n; } $message .= \r\nUser Client Info:\r\n; $message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent: .$_SERVER['HTTP_USER_AGENT'].\r\n\r\n; // NOTE: This code only builds the actual message, the headers are built elsewhere in the code. // This is our golf-package quote request (I work for a hotel) form, where you can book up to 7 tee times. Thus the iteration in the middle, to run through the 7 tee time fields. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looking for easier way to build email message
On Jan 24, 2008 6:20 PM, Rene Brehmer [EMAIL PROTECTED] wrote: Drew a blank off the archive, so here goes... I'm working on some forms for our company website, all of which simply have to be mailed to us by email. After verifying that the content of all the fields is valid and the proper type, it builds the email message as following. This all works great, but I want a simpler/easier way to reuse the code (we have 3 forms, with distinctively different content, but the mail process remains the same), so something that will do the below, but can be reduced to something like grabbing a text file and fill in the blanks would be nice, instead of this: // prepare message if(! $error) { $message = Information submitted with Tee Time booking form:\r\n; $message .= Name and address:\r\n\r\n; $message .= $name\r\n; $message .= $address\r\n; $message .= $city\r\n; $message .= $state $postcode\r\n\r\n; $message .= Email: $email\r\n; $message .= Phone: $phone\r\n; $message .= \r\n\r\nBooking info:\r\n\r\n; $message .= Arrival: $a_month $a_day\r\n; $message .= Departure: $d_month $d_day\r\n; $message .= Persons: $persons\r\n; $message .= Rooms: $rooms\r\n; $message .= \r\nGolf Courses\r\n\r\n; for($i = 1; $i 8; $i++) { if($_POST['course_'.$i] != 0) { $message .= 'Course: '.$_POST['course_'.$i].\r\n; $message .= 'Date: '.$_POST['month_'.$i].' '.$_POST['day_'.$i].\r\n; $message .= 'Time: '.$_POST['teetime_'.$i].\r\n; $message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n; } } if(! empty($comments)) { $message .= \r\nComments:\r\n$comments\r\n; } $message .= \r\nUser Client Info:\r\n; $message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent: .$_SERVER['HTTP_USER_AGENT'].\r\n\r\n; // NOTE: This code only builds the actual message, the headers are built elsewhere in the code. // This is our golf-package quote request (I work for a hotel) form, where you can book up to 7 tee times. Thus the iteration in the middle, to run through the 7 tee time fields. check the archives for smtp vs. mail(); somebody mentioned a number of classes available at this site: http://www.phpclasses.org some of them looked quite useful. -nathan
Re: [PHP] Looking for easier way to build email message
On Thu, January 24, 2008 5:20 pm, Rene Brehmer wrote: Drew a blank off the archive, so here goes... I'm working on some forms for our company website, all of which simply have to be mailed to us by email. After verifying that the content of all the fields is valid and the proper type, it builds the email message as following. This all works great, but I want a simpler/easier way to reuse the code (we have 3 forms, with distinctively different content, but the mail process remains the same), so something that will do the below, but can be reduced to something like grabbing a text file and fill in the blanks would be nice, instead of this: http://php.net/faq.php foreach($_POST as $field = $value){ $message .= $field: ; if (is_array($value)){ $message .= \r\n; foreach ($value as $f = $v){ $message .= strrepeat( , strlen($field) + 2) . $f: $v\r\n; } } else $message .= $value\r\n; } And get rid of your course_1, course_2, course_3... names and use: name=course[1], name=course[2], name=course[3] instead. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looking for easier way to build email message
a well known easy to use wrapper is phpmailer (STW), alternatively check out Manuel Lemos' mail related offerings at phpclasses.org (his code is, afaict, better but also a little more involved. Rene Brehmer schreef: Drew a blank off the archive, so here goes... I'm working on some forms for our company website, all of which simply have to be mailed to us by email. After verifying that the content of all the fields is valid and the proper type, it builds the email message as following. This all works great, but I want a simpler/easier way to reuse the code (we have 3 forms, with distinctively different content, but the mail process remains the same), so something that will do the below, but can be reduced to something like grabbing a text file and fill in the blanks would be nice, instead of this: // prepare message if(! $error) { $message = Information submitted with Tee Time booking form:\r\n; $message .= Name and address:\r\n\r\n; $message .= $name\r\n; $message .= $address\r\n; $message .= $city\r\n; $message .= $state $postcode\r\n\r\n; $message .= Email: $email\r\n; $message .= Phone: $phone\r\n; $message .= \r\n\r\nBooking info:\r\n\r\n; $message .= Arrival: $a_month $a_day\r\n; $message .= Departure: $d_month $d_day\r\n; $message .= Persons: $persons\r\n; $message .= Rooms: $rooms\r\n; $message .= \r\nGolf Courses\r\n\r\n; for($i = 1; $i 8; $i++) { if($_POST['course_'.$i] != 0) { $message .= 'Course: '.$_POST['course_'.$i].\r\n; $message .= 'Date: '.$_POST['month_'.$i].' '.$_POST['day_'.$i].\r\n; $message .= 'Time: '.$_POST['teetime_'.$i].\r\n; $message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n; } } if(! empty($comments)) { $message .= \r\nComments:\r\n$comments\r\n; } $message .= \r\nUser Client Info:\r\n; $message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent: .$_SERVER['HTTP_USER_AGENT'].\r\n\r\n; // NOTE: This code only builds the actual message, the headers are built elsewhere in the code. // This is our golf-package quote request (I work for a hotel) form, where you can book up to 7 tee times. Thus the iteration in the middle, to run through the 7 tee time fields. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looking for easier way to build email message
On Jan 24, 2008 6:20 PM, Rene Brehmer [EMAIL PROTECTED] wrote: Drew a blank off the archive, so here goes... I'm working on some forms for our company website, all of which simply have to be mailed to us by email. After verifying that the content of all the fields is valid and the proper type, it builds the email message as following. This all works great, but I want a simpler/easier way to reuse the code (we have 3 forms, with distinctively different content, but the mail process remains the same), so something that will do the below, but can be reduced to something like grabbing a text file and fill in the blanks would be nice, instead of this: // prepare message if(! $error) { $message = Information submitted with Tee Time booking form:\r\n; $message .= Name and address:\r\n\r\n; $message .= $name\r\n; $message .= $address\r\n; $message .= $city\r\n; $message .= $state $postcode\r\n\r\n; $message .= Email: $email\r\n; $message .= Phone: $phone\r\n; $message .= \r\n\r\nBooking info:\r\n\r\n; $message .= Arrival: $a_month $a_day\r\n; $message .= Departure: $d_month $d_day\r\n; $message .= Persons: $persons\r\n; $message .= Rooms: $rooms\r\n; $message .= \r\nGolf Courses\r\n\r\n; for($i = 1; $i 8; $i++) { if($_POST['course_'.$i] != 0) { $message .= 'Course: '.$_POST['course_'.$i].\r\n; $message .= 'Date: '.$_POST['month_'.$i].' '.$_POST['day_'.$i].\r\n; $message .= 'Time: '.$_POST['teetime_'.$i].\r\n; $message .= '# of golfers: '.$_POST['golfers_'.$i].\r\n; } } if(! empty($comments)) { $message .= \r\nComments:\r\n$comments\r\n; } $message .= \r\nUser Client Info:\r\n; $message .= 'User IP: '.$_SERVER['REMOTE_ADDR'].\r\nUser agent: .$_SERVER['HTTP_USER_AGENT'].\r\n\r\n; // NOTE: This code only builds the actual message, the headers are built elsewhere in the code. // This is our golf-package quote request (I work for a hotel) form, where you can book up to 7 tee times. Thus the iteration in the middle, to run through the 7 tee time fields. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Check out Zend_Mail. It changed my life. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php