Created
December 20, 2018 23:56
-
-
Save parzibyte/fae30ffdb38fa26f1030e1ca2b3061d2 to your computer and use it in GitHub Desktop.
This file contains 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 | |
function limpiarAsunto($asunto) | |
{ | |
$cadena = "Subject"; | |
$longitud = strlen($cadena) + 2; | |
return substr( | |
iconv_mime_encode( | |
$cadena, | |
$asunto, | |
[ | |
"input-charset" => "UTF-8", | |
"output-charset" => "UTF-8", | |
] | |
), | |
$longitud | |
); | |
} | |
$asunto = limpiarAsunto("Boletín semanal"); | |
$destinatario = "staff@gmail.com"; | |
$encabezados = "MIME-Version: 1.0" . "\r\n"; | |
# ojo, es una concatenación: | |
$encabezados .= "Content-type:text/html; charset=UTF-8" . "\r\n"; | |
$encabezados .= 'From: Luis Cabrera<contacto@parzibyte.me>' . "\r\n"; | |
$mensaje = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<title>Este es un mensaje</title> | |
<style type="text/css"> | |
h1{ | |
color: #8bc34a; | |
} | |
p{ | |
font-size: 1rem; | |
} | |
img{ | |
width: 10rem; | |
height: 10rem; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Este es un título con estilo</h1> | |
<p>Hola, mundo. Este es un mensaje largo</p> | |
<p> | |
También se pueden poner links: <a href="https://parzibyte.me/blog">parzibyte.me</a>,cosas | |
como <strong>negritas</strong> o <code>código</code>. Es decir, cualquier cosa que tenga que ver con HTML | |
puede enviarse en los correos. | |
</p> | |
<h1>Una imagen...</h1> | |
<img src="https://github.com/parzibyte.png"> | |
</body>'; | |
$mensaje = wordwrap($mensaje, 70, "\r\n"); | |
$resultado = mail($destinatario, $asunto, $mensaje, $encabezados); #Mandar al final los encabezados | |
if ($resultado) { | |
echo "Correo enviado"; | |
} else { | |
echo "Correo NO enviado"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment