Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Paste in response to yahoo answers question */
- $output = ''; // Will hold the HTML to display to the user, based on the request scenario.
- $HTML = Array( // $HTML Array to hold all the neccessary HTML
- 'form' => // The Form HTML
- '<form method="post">
- <p>Your name</p>
- <p>
- <input type="text" name="cf_name">
- </p>
- <p>Your e-mail</p>
- <p>
- <input type="text" name="cf_email">
- </p>
- <p>Subject</p>
- <p>
- <input type="text" name="cf_subject">
- </p>
- <p>Message</p>
- <p>
- <input type="text" name="cf_message">
- </p>
- <p>Who do you want to contact:</p>
- <p>
- <select name="cf_address" size="1">
- <option></option>
- <option disabled>--Group--</option>
- <option value="email"> Option</option>
- <option value="email"> Option</option>
- <option disabled>--Group--</option>
- <option value="email"> Option</option>
- <option disabled>--Group--</option>
- <option value="email"> Option</option>
- <option value="email"> Option</option>
- </select>
- </p>
- <input type="submit"value="Submit">
- <input type="reset" value="Clear">
- </form>
- ',
- 'success' => // The HTML for the success message
- '<h3>Thank You</h3>
- <p>Your message has been received. <br> We thank you for taking the time to message us.</p>
- <p>Someone will respond to your message as soon as possible.</p>
- ',
- 'error' => // Then HTML message for an error occuring
- '<h3>Internal Error</h3>
- <p>We\'re sorry to report that there has been an internal server error.</p>
- <p>Your message was not received. Please try again later.</p>
- <p>Sorry for any incovenience this has caused.</p>
- ');
- if( $_SERVER['REQUEST_METHOD'] === 'POST' ){ // If the page is requested using the 'POST' method, the way in which your form requests the results page.
- // You should have a function to check the inputs for "Email Injections". Google it!
- // You should also be checking to see if any of the important fields are left blank.
- $field_name = $_POST['cf_name'];
- $field_email = $_POST['cf_email'];
- $subject = $_POST['cf_subject'];
- $field_message = $_POST['cf_message'];
- $mail_to = $_POST['cf_address'];
- $body_message = 'From: '.$field_name."\n";
- $body_message .= 'E-mail: '.$field_email."\n";
- $body_message .= 'Message: '.$field_message;
- $headers = 'From: '.$cf_email."\r\n";
- $headers .= 'Reply-To: '.$cf_email."\r\n";
- $mail_status = mail($mail_to, $subject, $body_message, $headers);
- if ($mail_status) {
- $output = $HTML['success'];
- } else {
- $output = $HTML['error'];
- }
- }else{ // The request is a GET request
- $output = $HTML['form'];
- }
- echo $output;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement