Re: Looking for easier way to build email message
| From: | Richard Lynch | Date: | Fri, 25 Jan 2008 00:11:11 +0000 |
| Subject: | Re: Looking for easier way to build email message | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268058@lists.php.net to get a copy of this 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?