// SendAnyForm 0.1 snippet by Biep en Lu (www.biepenlu.nl) // Based on ContactMe 0.1 snippet for Etomite by Vassili Slessarenko // This snippet will send the data of all inputs in an HTML form // as an e-mail to the specified e-mail address. // Variables in snippet: // sendTo // formName // // Use snippet like this: // [[[email protected]&formName=Name_of_form]] // // To make the snippet work the following two chunks are needed: // $formName."_Form" : This chunk contains the HTML form code. // In this example the name of this chunk would be "Name_of_form_Form". // $formName."_Sent" : This chunk contains the HTML code to display when the form is sent // (Something like "thank you, we will contact you soon"). // In this example the name of this chunk would be "Name_of_form_Sent". // If these snippets do not exist the default form and sent message will be used (see VARIABLES). // // Input fields that need to be in the HTML form for the snippet to work: // // name : the name of the sender of the form. // Example HTML code: <input type="text" name="name" value="" size="40" /> // email : the e-mail address of the sender of the form. // Example HTML code: <input type="text" name="email" value="" size="40" /> // subject : the subject of the e-mail to be sent. // Example HTML code: <input type="text" name="subject" value="" size="40" /> // formSent : a hidden value to check if the form was sent. // The value of this hidden value should be yes. // Example HTML code: <input type="hidden" name="formSent" value="yes" /> // // Optional field to use in HTML form code: // // preSubject : can be used to supply a string which will always come before the user written subject. // This means you can for example filter the e-mails by subject and put them into a separate folder. // Example HTML code: <input type="hidden" name="preSubject" value="Contact form: " /> // There is no e-mail address validation or checking for required input fields in this snippet (yet) // Feel free to add this! // ### VARIABLES ### // X-Mailer value to appear in mail header $xMailer = "SendAnyForm PHP ".phpversion(); // Default form: if the chunk $formName."_Form" does not exist this default form will be used. $lineBreak = "\n"; $defaultForm = '<form action="" method="post">'.$lineBreak; $defaultForm .= '<p><label for="name">Name:<br />'.$lineBreak; $defaultForm .= '<input type="text" name="name" id="name" value="" size="40" /></label></p>'.$lineBreak; $defaultForm .= '<p><label for="email">E-mail:<br />'.$lineBreak; $defaultForm .= '<input type="text" name="email" id="email" value="" size="40" /></label></p>'.$lineBreak; $defaultForm .= '<p><label for="subject">Subject:<br />'.$lineBreak; $defaultForm .= '<input type="text" name="subject" id="subject" value="" size="40" /></label></p>'.$lineBreak; $defaultForm .= '<p><label for="content_text">Body:<br />'.$lineBreak; $defaultForm .= '<textarea name="content_text" id="content_text" rows="20" cols="32"></textarea></label></p>'.$lineBreak; $defaultForm .= '<p><input type="hidden" name="formSent" value="yes" />'.$lineBreak; $defaultForm .= '<input type="hidden" name="preSubject" value="Website reaction: " />'.$lineBreak; $defaultForm .= '<input type="reset" value="Clear" /> <input type="submit" value="Send message" /></p>'.$lineBreak; $defaultForm .= '</form>'.$lineBreak; // Default sent: if the chunk $formName."_Sent" does not exist this default thank you message will be used. $defaultSent = '<p>Thank you for your message.</p>'; // ### CODE ### // (no need to change anything under here) // Hidden values in HTML used to send the form, wich should not be sent themselves $hiddenVal = array("preSubject", "formSent"); if (isset($_POST['formSent']) && $_POST['formSent'] == 'yes') { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; if (isset($_POST['preSubject'])) { $subject = $_POST['preSubject'].$subject; } $message = ""; foreach ($_POST as $key => $value) { $doNotInclude = 0; foreach($hiddenVal as $val) { if ($key == $val) { $doNotInclude = 1; } } if ($doNotInclude == 0) { $message .= $key.": ".stripslashes($value)."\r\n\r\n"; } } $headers = "From: $name <$email>\r\n"; $headers .= "X-Mailer: $xMailer\r\n"; mail ($sendTo, $subject, $message, $headers); $output = $etomite->putChunk($formName."_Sent"); if (strlen($output) > 0) { return $output; } else { return $defaultSent; } } else { $output = $etomite->putChunk($formName."_Form"); if (strlen($output) > 0) { return $output; } else { return $defaultForm; } }
I am running this snippet on one of my sites without any modifications.
You MUST call the snippet uncached!
[[email protected]&formName=Name_of_form!]