Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2. // Ajax Functions
  3. function bberri_phpmailer( $phpmailer ) {
  4.     $phpmailer->IsSMTP();     //switch to smtp
  5.     $phpmailer->Host = 'smtp.gmail.com';
  6.     $phpmailer->Port = 587;
  7.     $phpmailer->Username = 'contacto@bberri.cl';
  8.     $phpmailer->Password = 'Contacto_2017';
  9. }
  10. function acripal_send_contact_form() {
  11.  
  12.   $name = wp_strip_all_tags($_POST['name']);
  13.   $email = wp_strip_all_tags($_POST['email']);
  14.   $message = wp_strip_all_tags($_POST['message']);
  15.  
  16.   if($name && $email && $message){
  17.     $to        = 'mail@gabrielescobar.cl';
  18.     $subject   = 'Nuevo Mensaje - Formulario de Contacto '.get_bloginfo('name').' Website';
  19.  
  20.     $body = 'Nombre: '.$name."\n";
  21.     $body .= 'E-mail: '.$email."\n";
  22.     $body .= 'Mensaje: '.$message."\n";
  23.     $body .= 'Enviado el '.date('d/m/Y G:i');
  24.  
  25.     $headers[] = 'From: '.get_bloginfo('name').' <'.$to.'>';
  26.     $headers[] = 'Reply-To: '.$name.' <'.$email.'>';
  27.     $headers[] = 'MIME-Version: 1.0';
  28.     $headers[] = 'Content-Type: text/plain; charset='.get_bloginfo('charset');
  29.  
  30.     wp_mail($to, $subject, $body, $headers);
  31.     echo 1;
  32.  
  33.   } else {
  34.  
  35.  
  36.     echo 0;
  37.     wp_send_json_error();
  38.  
  39.   }
  40.  
  41.   die();
  42.  
  43. }
  44. add_action( 'phpmailer_init', 'bberri_phpmailer' );
  45. add_action('wp_ajax_nopriv_acripal_send_user_contact_form', 'acripal_send_contact_form');
  46. add_action('wp_ajax_acripal_send_user_contact_form', 'acripal_send_contact_form');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement