Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active May 24, 2021 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseluisq/709543d65cbfc117168d760e5223f76a to your computer and use it in GitHub Desktop.
Save joseluisq/709543d65cbfc117168d760e5223f76a to your computer and use it in GitHub Desktop.
PHPMailer: Ejemplo de envío de email simple.
<?php
/**
* PHPMailer: Ejemplo de envío de email simple.
*/
require __DIR__ . '/class.phpmailer.php';
// Crear una instancia de la clase PHPMailer
$mail = new PHPMailer;
// Envio de email simple
$mail->isMail();
// Desplegar errores y activar el debug
$mail->SMTPDebug = 4;
// Email del remitente (puedes poner algun email de prueba)
$mail->setFrom('from@example.com', 'Nombre Apellido');
// Email del destinatario (a quíen se enviará el mensaje)
$mail->addAddress('whoto@example.com', 'Nombre Apellido');
// Aquí agregar el asunto del mensaje
$mail->Subject = 'ASUNTO DEL MENSAJE';
// Escribir el mensaje HTML
$message = '<h1>MENSAJE HTML</h1>';
$mail->msgHTML($message);
// Enviar el mensaje y verificar si existen errores
if ($mail->send()) {
echo "MENSAJE SE HA ENVIADO";
} else {
echo "ERROR AL ENVIAR MENSAJE";
}
@angelcepda
Copy link

buenas tarder, gracias por sus aportes, me pregunto si me pueden apoyar, he utilizado las clase como lo indican y me sale siempre error en linea 19,

Call to undefined method PHPMailer::setFrom() in C:\wamp\www\php_mailer_2_lib\envio_simple.php on line 19

@KL3YB3R
Copy link

KL3YB3R commented May 24, 2021

Buenas! Quisiera saber si me pueden ayudar respecto a añadir un temporizador para el mensaje, hice el procedimiento y funciona, pero no se como hacer que luego de un determinado tiempo se elimine el mensaje. Gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment