Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_cache_limiter('nocache');
- header('Expires: ' . gmdate('r', 0));
- header('Content-type: application/json');
- require 'php-mailer/class.phpmailer.php';
- // Your email address
- $to = 'jhoedram@gmail.com';
- $subject = 'Contacto desde mi sitio web!';
- if($to) {
- $fields = array(
- 0 => array(
- 'text' => 'Nombre',
- 'val' => $_POST['nombre']
- ),
- 1 => array(
- 'text' => 'Correo',
- 'val' => $_POST['email']
- ),
- 2 => array(
- 'text' => 'Telefono',
- 'val' => $_POST['telefono']
- ),
- 3 => array(
- 'text' => 'Mensaje',
- 'val' => $_POST['mensaje']
- ),
- 4 => array(
- 'text' => 'IP',
- 'val' => $_SERVER['REMOTE_ADDR']
- ),
- 5 => array(
- 'text' => 'Acerca de Navegador',
- 'val' => $_SERVER['HTTP_USER_AGENT']
- )
- );
- $message = "";
- foreach($fields as $field) {
- $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br><br>\n";
- }
- $mail = new PHPMailer;
- $mail->IsSMTP(); // Set mailer to use SMTP
- // Optional Settings
- $mail->Host = 'borrado'; // Specify main and backup server
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'borrado'; // SMTP username
- $mail->Password = '********'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- $mail->From = 'remitente@gmail.com';
- $mail->FromName = 'Jhon!';
- $mail->AddAddress($to); // Add a recipient
- $mail->AddReplyTo('remitente@gmail.com');
- $mail->IsHTML(true); // Set email format to HTML
- $mail->CharSet = 'UTF-8';
- $mail->Subject = $subject;
- $mail->Body = $message;
- if(!$mail->Send()) {
- $arrResult = array ('response'=>'error');
- }
- $arrResult = Header("Location: ../exito.html");
- exit();
- echo json_encode($arrResult);
- } else {
- $arrResult = array ('response'=>'error');
- echo json_encode($arrResult);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement