Advertisement
Guest User

Untitled

a guest
Nov 30th, 2017
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 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 = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
  16. $mail->SMTPAuth = true; // Enable SMTP authentication
  17. $mail->Username = 'user@example.com'; // SMTP username
  18. $mail->Password = 'secret'; // SMTP password
  19. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  20. $mail->Port = 587; // TCP port to connect to
  21.  
  22. //Recipients
  23. $mail->setFrom('from@example.com', 'Mailer');
  24. $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
  25. $mail->addAddress('ellen@example.com'); // Name is optional
  26. $mail->addReplyTo('info@example.com', 'Information');
  27. $mail->addCC('cc@example.com');
  28. $mail->addBCC('bcc@example.com');
  29.  
  30. //Attachments
  31. $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  32. $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  33.  
  34. //Content
  35. $mail->isHTML(true); // Set email format to HTML
  36. $mail->Subject = 'Here is the subject';
  37. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  38. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  39.  
  40. $mail->send();
  41. echo 'Message has been sent';
  42. } catch (Exception $e) {
  43. echo 'Message could not be sent.';
  44. echo 'Mailer Error: ' . $mail->ErrorInfo;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement