Advertisement
Guest User

PHPMailer

a guest
Feb 1st, 2019
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. // Definir ruta principal
  4. define('HOMEDIR',__DIR__);
  5.  
  6. use PHPMailer\PHPMailer\PHPMailer;
  7. use PHPMailer\PHPMailer\Exception;
  8.  
  9. require HOMEDIR.'/PHPMailer/Exception.php';
  10. require HOMEDIR.'/PHPMailer/PHPMailer.php';
  11. require HOMEDIR.'/PHPMailer/SMTP.php';
  12.  
  13. $mail = new PHPMailer(true);
  14. try {
  15.     //Server settings
  16.     $mail->SMTPDebug = 2;                                 // Enable verbose debug output
  17.     $mail->isSMTP();                                      // Set mailer to use SMTP
  18.     $mail->Host = 'mail.*******.com';  // Specify main and backup SMTP servers
  19.     $mail->SMTPAuth = true;                               // Enable SMTP authentication
  20.     $mail->Username = 'account@*******.com';                 // SMTP username
  21.     $mail->Password = '***********';                           // SMTP password
  22.     $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  23.     $mail->Port = 465;                                    // TCP port to connect to
  24.  
  25.     //Recipients
  26.     $mail->setFrom('account@********.com', 'Cuentas');
  27.     $mail->addAddress('********@gmail.com');     // Add a recipient
  28.     //$mail->addAddress('ellen@example.com');               // Name is optional
  29.     $mail->addReplyTo('account@tuberfly.com', 'TuberFly Cuentas');
  30.     //$mail->addCC('cc@example.com');
  31.     //$mail->addBCC('bcc@example.com');
  32.  
  33.     //Attachments
  34.     //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
  35.     //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
  36.  
  37.     //Content
  38.     $mail->isHTML(true);                                  // Set email format to HTML
  39.     $mail->Subject = 'Bienvenido';
  40.     $mail->Body    = 'Te has registrado <b>correctamente</b> en ***** y ahora ya puedes comenzar a usar nuestros servicios.';
  41.     $mail->AltBody = 'Te has registrado correctamente en ********* y ahora ya puedes comenzar a usar nuestros servicios.';
  42.  
  43.     $mail->send();
  44.     echo 'El mensaje ha sido enviado correctamente';
  45. } catch (Exception $e) {
  46.     echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement