Created
April 28, 2015 20:19
-
-
Save nicocedron/0201c9e368250524cb76 to your computer and use it in GitHub Desktop.
Send Email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<?php echo $message; ?> | |
</body> | |
</html> | |
<?php | |
$content = ob_get_contents(); | |
ob_end_clean(); | |
return $content; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
/********************************/ | |
/* SEND MAIL by NicoCedron */ | |
/*******************************/ | |
function escape_string($string){ | |
return htmlspecialchars(strip_tags($string)); | |
} | |
foreach($_POST as $key=>$value){ | |
$$key = escape_string($value); | |
} | |
$errors = array(); | |
if(empty($name)) | |
$errors[] = 'Debe ingresar el nombre'; | |
if(empty($message)) | |
$errors[] = 'Debe ingresar el mensaje'; | |
if(count($errors)){ | |
echo json_encode( array('result'=> 0, 'errors'=> $errors) ); | |
exit(); | |
} | |
$SEND_TO = '[email protected]'; | |
$SUBJECT = 'Atencion con cambio de tarifas'; | |
// Cuerpo o mensaje | |
$CONTENT = include('email_template.php'); | |
$HEADERS = 'MIME-Version: 1.0' . "\r\n"; | |
$HEADERS .= 'Content-type: text/html; charset=utf-8' . "\r\n"; | |
$HEADERS .= 'From: CONTACT <[email protected]>' . "\r\n"; | |
$mail = mail($SEND_TO, $SUBJECT, $CONTENT, $HEADERS); | |
if($mail) | |
echo json_encode( array('result'=> 1) ); | |
else{ | |
$errors[] = 'Error al enviar el email'; | |
echo json_encode( array('result'=> 0, 'errors'=> $errors) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment