Advertisement
Guest User

contactform

a guest
Jun 8th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.  
  3. session_cache_limiter('nocache');
  4. header('Expires: ' . gmdate('r', 0));
  5.  
  6. header('Content-type: application/json');
  7.  
  8. require 'php-mailer/class.phpmailer.php';
  9.  
  10. // Your email address
  11. $to = 'jhoedram@gmail.com';
  12.  
  13. $subject = 'Contacto desde mi sitio web!';
  14.  
  15. if($to) {
  16.    
  17.     $fields = array(
  18.         0 => array(
  19.             'text' => 'Nombre',
  20.             'val' => $_POST['nombre']
  21.         ),
  22.         1 => array(
  23.             'text' => 'Correo',
  24.             'val' => $_POST['email']
  25.         ),
  26.         2 => array(
  27.             'text' => 'Telefono',
  28.             'val' => $_POST['telefono']
  29.         ),
  30.         3 => array(
  31.             'text' => 'Mensaje',
  32.             'val' => $_POST['mensaje']
  33.         ),
  34.         4 => array(
  35.             'text' => 'IP',
  36.             'val' => $_SERVER['REMOTE_ADDR']
  37.         ),
  38.         5 => array(
  39.             'text' => 'Acerca de Navegador',
  40.             'val' => $_SERVER['HTTP_USER_AGENT']
  41.         )
  42.     );
  43.    
  44.     $message = "";
  45.    
  46.     foreach($fields as $field) {
  47.         $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br><br>\n";
  48.     }
  49.    
  50.     $mail = new PHPMailer;
  51.  
  52.     $mail->IsSMTP();                                      // Set mailer to use SMTP
  53.    
  54.     // Optional Settings
  55.     $mail->Host = 'borrado';                            // Specify main and backup server
  56.     $mail->SMTPAuth = true;                                     // Enable SMTP authentication
  57.     $mail->Username = 'borrado';                // SMTP username
  58.     $mail->Password = '********';       // SMTP password
  59.     $mail->SMTPSecure = 'tls';                                  // Enable encryption, 'ssl' also accepted
  60.  
  61.     $mail->From = 'remitente@gmail.com';
  62.     $mail->FromName = 'Jhon!';
  63.     $mail->AddAddress($to);                               // Add a recipient
  64.     $mail->AddReplyTo('remitente@gmail.com');
  65.  
  66.     $mail->IsHTML(true);                                  // Set email format to HTML
  67.    
  68.     $mail->CharSet = 'UTF-8';
  69.  
  70.     $mail->Subject = $subject;
  71.     $mail->Body    = $message;
  72.  
  73.     if(!$mail->Send()) {
  74.        $arrResult = array ('response'=>'error');
  75.     }
  76.  
  77.     $arrResult = Header("Location: ../exito.html");
  78. exit();
  79.  
  80.     echo json_encode($arrResult);
  81.    
  82. } else {
  83.  
  84.     $arrResult = array ('response'=>'error');
  85.     echo json_encode($arrResult);
  86.  
  87. }
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement