Guest User

Untitled

a guest
Dec 7th, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2. use PHPMailerPHPMailerPHPMailer;
  3. use PHPMailerPHPMailerException;
  4.  
  5. require 'path/to/PHPMailer/src/Exception.php';
  6. require 'path/to/PHPMailer/src/PHPMailer.php';
  7. require 'path/to/PHPMailer/src/SMTP.php';
  8.  
  9. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  10. try {
  11. //Server settings
  12. $mail->SMTPDebug = 2; // Enable verbose debug output
  13. $mail->isSMTP(); // Set mailer to use SMTP
  14. $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
  15. $mail->SMTPAuth = true; // Enable SMTP authentication
  16. $mail->Username = 'user@example.com'; // SMTP username
  17. $mail->Password = 'secret'; // SMTP password
  18. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  19. $mail->Port = 587; // TCP port to connect to
  20.  
  21. //Recipients
  22. $mail->setFrom('from@example.com', 'Mailer');
  23. $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
  24. $mail->addAddress('ellen@example.com'); // Name is optional
  25. $mail->addReplyTo('info@example.com', 'Information');
  26. $mail->addCC('cc@example.com');
  27. $mail->addBCC('bcc@example.com');
  28.  
  29. //Attachments
  30. $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  31. $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  32.  
  33. //Content
  34. $mail->isHTML(true); // Set email format to HTML
  35. $mail->Subject = 'Here is the subject';
  36. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  37. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  38.  
  39. $mail->send();
  40. echo 'Message has been sent';
  41. } catch (Exception $e) {
  42. echo 'Message could not be sent.';
  43. echo 'Mailer Error: ' . $mail->ErrorInfo;
  44. }
Add Comment
Please, Sign In to add comment