Skip to content

Instantly share code, notes, and snippets.

@nicocedron
Created April 28, 2015 20:19
Show Gist options
  • Save nicocedron/0201c9e368250524cb76 to your computer and use it in GitHub Desktop.
Save nicocedron/0201c9e368250524cb76 to your computer and use it in GitHub Desktop.
Send Email
<?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;
?>
<?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