PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY If (Unlimited web hosting)

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY If you want to send the email in an encoding other than iso-8859-1 (English and Western European), you need to set the Content-Type header. For Unicode (UTF-8), set it like this: $additionalHeaders = “Content-Type: text/plain; charset=utf-8rn”; The web page that the form is embedded in must use the same encoding (usually set in a tag). Hard-coded additional headers like this present no security risk, but anything that comes from user input must be filtered before it s used. So, let s take a look at incorporating the user s email address into a Reply-To header. Although PHP Solution 5-5 should sanitize any user input, it s worth subjecting the email field to a more rigorous check. PHP Solution 5-6: Automating the reply address Continue working with the same page. Alternatively, use contact08.php from the download files. 1. Although I suggested at the end of PHP Solution 5-3 that you add the email field to the $required array, there may be occasions when you don t want to make it required. So, it makes more sense to keep the code to validate the email address separate from the main loop that processes the $_POST array. If email is required, but has been left blank, the loop will have already added email to the $missing array, so the message won t get sent anyway. If it s not a required field, you need to check $email only if it contains something. So you need to wrap the validation code in an if statement that uses !empty(). An exclamation mark is the negative operator, so you read this as not empty. Insert the code shown in bold immediately after the loop that processes the $_POST array. It contains a complex line, so you may prefer to copy it from contact09.php. // otherwise, assign to a variable of the same name as $key elseif (in_array($key, $expected)) { ${$key} = $temp; } } } // validate the email address if (!empty($email)) { // regex to ensure no illegal characters in email address $checkEmail = ‘/^[^@]+@[^srn’”;,@%]+$/’; // reject the email address if it doesn’t match if (!preg_match($checkEmail, $email)) { array_push($missing, ‘email’); } }
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Leave a Reply