onetone_contact

Send email ---------------------------------------------------------------------.

Description

onetone_contact(); 

Usage

  1. if ( !function_exists( 'onetone_contact' ) ) { 
  2. require_once '/includes/theme-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = onetone_contact(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/theme-functions.php  
  1. function onetone_contact() { 
  2. if(trim($_POST['Name']) === '') { 
  3. $Error = __('Please enter your name.', 'onetone'); 
  4. $hasError = true; 
  5. } else { 
  6. $name = trim($_POST['Name']); 
  7.  
  8. if(trim($_POST['Email']) === '') { 
  9. $Error = __('Please enter your email address.', 'onetone'); 
  10. $hasError = true; 
  11. } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2, 4}$/i", trim($_POST['Email']))) { 
  12. $Error = __('You entered an invalid email address.', 'onetone'); 
  13. $hasError = true; 
  14. } else { 
  15. $email = trim($_POST['Email']); 
  16.  
  17. if(trim($_POST['Message']) === '') { 
  18. $Error = __('Please enter a message.', 'onetone'); 
  19. $hasError = true; 
  20. } else { 
  21. if(function_exists('stripslashes')) { 
  22. $message = stripslashes(trim($_POST['Message'])); 
  23. } else { 
  24. $message = trim($_POST['Message']); 
  25.  
  26. if(!isset($hasError)) { 
  27. if (isset($_POST['sendto']) && preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2, 4}$/i", trim($_POST['sendto']))) { 
  28. $emailTo = $_POST['sendto']; 
  29. else{ 
  30. $emailTo = get_option('admin_email'); 
  31. if($emailTo !="") { 
  32. $subject = 'From '.$name; 
  33. $body = "Name: $name \n\nEmail: $email \n\nMessage: $message"; 
  34. $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; 
  35.  
  36. wp_mail($emailTo, $subject, $body, $headers); 
  37. $emailSent = true; 
  38. echo json_encode(array("msg"=>__("Your message has been successfully sent!", "onetone"), "error"=>0)); 
  39.  
  40. else 
  41. echo json_encode(array("msg"=>$Error, "error"=>1)); 
  42. die() ;