From a4e42e7c89f4c256ff2512902fb539a2279785ce Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Thu, 8 Feb 2007 00:28:20 -0500 Subject: [PATCH] improved documentation for email(), added error reporting to metaform, allowed periods in email() subjects improved mod_rewrite example in run.php --- email.php | 11 ++++++++--- metaform/template.html | 4 ++++ metaform/template.php | 16 +++++++++++----- run.php | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/email.php b/email.php index 5d119fc..abd02e8 100644 --- a/email.php +++ b/email.php @@ -24,8 +24,13 @@ # This function will SAFELY send e-mail (ie you can pass parameters to it # that you got from a form and not worry about header injection.) Weird # characters are stripped from the $subject and from the real names, but e-mail -# addresses are not modified at all. If an e-mail address is invalid this -# function will return non-zero. +# addresses are not modified at all. + +# RETURN values: +# 0: e-mail successfully accepted for delivery +# 1: badly formatted "from" address +# 2: badly formatted "to" address +# 5: message rejected by mail() (reason unknown) # You cannot pass more than one address to any parameter # address fields (from, to, cc, bcc) can be in either of these formats: @@ -40,7 +45,7 @@ function email($from, $to, $subject, $message, $cc = '', $bcc = '') { if($to == '') { return 2; } #FIXME should allow many more characters here - $subject = ereg_replace("[^a-zA-Z _'-]", '_', $subject); + $subject = ereg_replace("[^a-zA-Z _'.-]", '_', $subject); $headers = "From: $from"; if($cc) { diff --git a/metaform/template.html b/metaform/template.html index 85dd4d6..ed5b202 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -5,6 +5,8 @@ ~form_name~ entry @@ -12,6 +14,8 @@ td.caption { text-align: right; vertical-align: top; font-weight: bold; }

~form_name~ entry form

+

~error_message.html~

+
diff --git a/metaform/template.php b/metaform/template.php index 5a5c0ee..af98d96 100644 --- a/metaform/template.php +++ b/metaform/template.php @@ -86,12 +86,18 @@ function ~form_name~() { $message = tem_run('~form_name~.email.txt'); $cc = ''; $bcc = ''; - email($from, $to, $subject, $message, $cc, $bcc); + if(email($from, $to, $subject, $message, $cc, $bcc)) { + tem_set('error_message', 'Due to an internal error, your message could not be sent. Please try again later.'); + tem_sub('error'); + $error = true; + } + } + if($error !== true) { + tem_load('~form_name~.html'); + tem_sub('thankyou'); + tem_output(); + exit(); } - tem_load('~form_name~.html'); - tem_sub('thankyou'); - tem_output(); - exit(); } # otherwise, we display the form again. ~form_name~_get_fields() has # already put the posted values back into the template engine, so they will diff --git a/run.php b/run.php index 20b3111..3eca719 100644 --- a/run.php +++ b/run.php @@ -54,7 +54,7 @@ # RewriteEngine on # RewriteRule ^$ /foo/run.php -# RewriteRule .*\.html$ /foo/run.php +# RewriteRule ^/foo/[^/]*\.html$ /foo/run.php require_once('code/wfpl/file_run.php'); -- 1.7.10.4