Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['email'])) { require_once "Mail.php"; //PEA>Homepage is already installed in our current environment
  4.  
  5. $email_to = "example@address.com"; //Enter the email you want to send the form to $email_subject = "JCM's Security and Services"; // You can put whatever subject here
  6.  
  7. $host = "address.ipage.com"; // The hostname of your mail server // If your email is with HostMySite, use the actual hostname of your mail server, for example: // SmarterMail: mailXX.safesecureweb.com OR win-mailXX.hostmanagement.net // OpenX-change: smtp.hostmanagement.net // Contact Support if you aren't sure what to enter here.
  8.  
  9. $username = "example@address.com"; // A valid email address you have setup $from_address = "example@address.com"; // If your mail is hosted with HostMySite this has to match the email address above $password = "password"; // Password for the abom"; //Enter the email you want customers to reply to $port = "587"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with HostMySite
  10.  
  11. function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); }
  12.  
  13. // Validate expected data exists if(!isset($_POST['salutation']) || !isset($_POST['fname']) || !isset($_POST['lname']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); }
  14.  
  15. $salutation = $_POST['salutation']; // required $first_name = $_POST['fname']; // required $last_name = $_POST['lname']; // required $email_from = $_POST['email']; // required $phone = $_POST['phone']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($message) < 2) { $error_message .= 'The message you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.nn"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Salutation: ".clean_string($salutation)."n"; $email_message .= "First Name: ".clean_string($first_name)."n"; $email_message .= "Last Name: ".clean_string($last_name)."n"; $email_message .= "Email: ".clean_string($email_from)."n"; $email_message .= "Phone: ".clean_string($phone)."n"; $email_message .= "Message: ".clean_string($message)."n";
  16.  
  17. // This section creates the email headers $auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password, 'port' => $port); $headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
  18.  
  19. $smtp = Mail::factory('smtp', $auth); $mail = $smtp->send($email_to, $headers, $email_message);
  20.  
  21. if (PEAR::isError($mail)) {?> <!– include your own failure message html here –> Unfortunately, the message could not be sent at this time. Please try again later.
  22.  
  23. <!– Uncomment the line below to see errors with sending the message –> <!– <?php echo("<p>". $mail->getMessage()."</p>"); ?> –>
  24.  
  25. <?php } else { ?>
  26.  
  27. <!– include your own success message html here –>
  28.  
  29. header("Location: http://www.example.com/thank.php");
  30.  
  31. <?php } } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement