Guest User

Untitled

a guest
Jun 29th, 2018
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 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 'PHPMailer/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.niravmadariya.com;smtp2.niravmadariya.com'; // Specify main and backup SMTP servers
  16. $mail->SMTPAuth = true; // Enable SMTP authentication
  17. $mail->Username = 'mail@niravmadariya.com'; // SMTP username
  18. $mail->Password = 'AV3ry$tr0ngP@s5woRd'; // 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('no-reply@niravmadariya.com', 'AutoMailer');
  24. $mail->addAddress('niravmadariya@gmail.com', 'Nirav Madariya'); // Add a recipient
  25. $mail->addAddress('niravmadariya@outlook.com'); // Name is optional
  26. $mail->addReplyTo('info@niravmadariya.com', 'Query');
  27. $mail->addCC('niravmadariya@outlook.in');
  28. $mail->addBCC('niravmadariya@outlook.com');
  29.  
  30. //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 = 'This is ridiculous';
  36. $mail->Body = 'This is the ridiculous message body <b>in bold!</b>';
  37. $mail->AltBody = 'This is the body for non-ridiculous mail clients';
  38.  
  39. $mail->send();
  40. echo 'Message has been sent';
  41. } catch (Exception $e) {
  42. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  43. }
Add Comment
Please, Sign In to add comment