Advertisement
CalMagal

Enviando Email com PHPMailer

Dec 8th, 2018
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1.   use PHPMailer\PHPMailer\PHPMailer;
  2.   use PHPMailer\PHPMailer\Exception;
  3.  
  4.   require 'phpmailer/vendor/phpmailer/phpmailer/src/Exception.php';
  5.   require 'phpmailer/vendor/phpmailer/phpmailer/src/PHPMailer.php';
  6.   require 'phpmailer/vendor/phpmailer/phpmailer/src/SMTP.php';
  7.   require 'phpmailer/vendor/autoload.php';
  8.  
  9.   $mail = new PHPMailer(true);
  10.   $USERNAME = "SEU EMAIL AQUI";
  11.   $PASSWORD = "A SENHA DO SEU EMAIL AQUI";
  12.   $NAME_FROM = "NOME";
  13.   $mail->WordWrap = 50;
  14.   $mail->isHTML(true);
  15.   $mail->SMTPSecure = 'ssl';
  16.   $mail->isSMTP();
  17.   $mail->SMTPDebug = 0;
  18.   $mail->Host = 'smtp.gmail.com';
  19.   $mail->Port = 465;
  20.   $mail->SMTPAuth = true;
  21.   $mail->SMTPOptions = array(
  22.       'ssl' => array(
  23.           'verify_peer' => false,
  24.           'verify_peer_name' => false,
  25.           'allow_self_signed' => false
  26.       )
  27.   );
  28.  
  29.   $email_destino_principal = "xxxxxxxx@xxxxxxxx.com";
  30.   $email_destino_secundario = "xxxxxxxx@xxxxxxxx.com";
  31.  
  32.   $html = "AQUI VOCÊ COLOCA O CONTEÚDO DA MENSAGEM";
  33.  
  34.   try {
  35.    
  36.     $subject        = "AQUI O ASSUNTO";
  37.     $mail->Username = $USERNAME;
  38.     $mail->Password =$PASSWORD;
  39.     $mail->setFrom($USERNAME,$NAME_FROM);
  40.     $mail->addAddress($email_destino_principal);
  41.     $mail->AddCC($email_destino_secundario);
  42.  
  43.     $mail->Subject = ($subject);
  44.     $mail->msgHTML($html);
  45.     $mail->send();
  46.     echo 'Email enviado com suesso!';
  47.   } catch (Exception $e) {
  48.       echo 'Não foi possível enviar email';
  49.       echo 'Aconteceu o seguinte erro: ' . $mail->ErrorInfo;
  50.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement