zedg Posted May 2, 2008 Share Posted May 2, 2008 Hi, I am using a php form that I got from easykiss123.com which works well, however I wanted to know if the script can be slightly modded so that the form submits to an email address AND a file - a csv file. ?? Any help would be appreciated. !! Script is below.. <?php include('corefuncs.php'); if (function_exists('nukeMagicQuotes')) { nukeMagicQuotes(); } // process the email if (array_key_exists('send', $_POST)) { $to = '[email protected]'; // use your own email address $subject = 'Website Enquiry'; // list expected fields $expected = array('firstname', 'familyname', 'phone', 'fax', 'email', 'company', 'street', 'city', 'country', 'enquiry'); // set required fields $required = array('name', 'email'); // create empty array for any missing fields $missing = array(); // assume that there is nothing suspect $suspect = false; // create a pattern to locate suspect phrases $pattern = '/Content-Type:|Bcc:|Cc:/i'; // function to check for suspect phrases function isSuspect($val, $pattern, &$suspect) { // if the variable is an array, loop through each element // and pass it recursively back to the same function if (is_array($val)) { foreach ($val as $item) { isSuspect($item, $pattern, $suspect); } } else { // if one of the suspect phrases is found, set Boolean to true if (preg_match($pattern, $val)) { $suspect = true; } } } // check the $_POST array and any sub-arrays for suspect content isSuspect($_POST, $pattern, $suspect); if ($suspect) { $mailSent = false; unset($missing); } else { // process the $_POST variables foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { array_push($missing, $key); } // 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 = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; // reject the email address if it doesn't match if (!preg_match($checkEmail, $email)) { array_push($missing, 'email'); } } // go ahead only if not suspect and all required fields OK if (!$suspect && empty($missing)) { // build the message $message = "First_Name: $firstname\n\n"; $message .= "Family_Name: $familyname\n\n"; $message .= "Phone: $phone\n\n"; $message .= "Fax: $fax\n\n"; $message .= "Email: $email\n\n"; $message .= "Company_Name: $company\n\n"; $message .= "Street_Address: $street\n\n"; $message .= "City: $city\n\n"; $message .= "Country: $country\n\n"; $message .= "Enquiry: $enquiry"; // limit line length to 130 characters $message = wordwrap($message, 130); // create additional headers $additionalHeaders = 'From: Company Name<[email protected]>'; if (!empty($email)) { $additionalHeaders .= "\r\nReply-To: $email"; } // send it $mailSent = mail($to, $subject, $message, $additionalHeaders); if ($mailSent) { // $missing is no longer needed if the email is sent, so unset it unset($missing); } } } ?> Link to comment https://forums.phpfreaks.com/topic/103833-php-form-help-please/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.