Guest User

Untitled

a guest
Jun 5th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php
  2. // Import PHPMailer classes into the global namespace
  3. // These must be at the top of your script, not inside a function
  4. use PHPMailer\PHPMailer\PHPMailer;
  5. use PHPMailer\PHPMailer\Exception;
  6.  
  7. //Load Composer's autoloader
  8. require 'vendor/autoload.php';
  9.  
  10. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  11. try {
  12. //Server settings
  13. $mail->SMTPDebug = 2; // Enable verbose debug output
  14. $mail->isSMTP(); // Set mailer to use SMTP
  15. $mail->Host = '...'; // Specify main and backup SMTP servers
  16. $mail->SMTPAuth = true; // Enable SMTP authentication
  17. $mail->Username = '...'; // SMTP username
  18. $mail->Password = '...'; // SMTP password
  19. $mail->SMTPSecure = '...'; // Enable TLS encryption, `ssl` also accepted
  20. $mail->Port = ...; // TCP port to connect to
  21.  
  22. [...] corpo do e-mail [...]
  23.  
  24. //Attachments [Arquivo]
  25. $mail->addAttachment('/var/tmp/file.tar.gz'); # Adiciona arquivo
  26. $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); # nome opcional
  27.  
  28. $mail->send();
  29. echo 'Message has been sent';
  30. } catch (Exception $e) {
  31. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  32. }
Add Comment
Please, Sign In to add comment