SHARE
TWEET

Untitled

a guest Jul 16th, 2019 381 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * This example shows settings to use when sending via Google's Gmail servers.
  5.  * This uses traditional id & password authentication - look at the gmail_xoauth.phps
  6.  * example to see how to use XOAUTH2.
  7.  * The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
  8.  */
  9. //Import PHPMailer classes into the global namespace
  10. use PHPMailer\PHPMailer\PHPMailer;
  11. // require '../vendor/autoload.php';
  12. require '../../../Users/snarl/vendor/autoload.php';
  13.  
  14. //Create a new PHPMailer instance
  15. $mail = new PHPMailer;
  16. //Tell PHPMailer to use SMTP
  17. $mail->isSMTP();
  18. //Enable SMTP debugging
  19. // 0 = off (for production use)
  20. // 1 = client messages
  21. // 2 = client and server messages
  22. $mail->SMTPDebug = 2;
  23. //Set the hostname of the mail server
  24. $mail->Host = 'smtp.gmail.com';
  25. // use
  26. // $mail->Host = gethostbyname('smtp.gmail.com');
  27. // if your network does not support SMTP over IPv6
  28. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  29. $mail->Port = 587;
  30. //Set the encryption system to use - ssl (deprecated) or tls
  31. $mail->SMTPSecure = 'tls';
  32. //Whether to use SMTP authentication
  33. $mail->SMTPAuth = true;
  34. //Username to use for SMTP authentication - use full email address for gmail
  35. $mail->Username = "my_username@gmail.com";
  36. //Password to use for SMTP authentication
  37. $mail->Password = "my_password";
  38. //Set who the message is to be sent from
  39. $mail->setFrom('from@example.com', 'First Last');
  40. //Set an alternative reply-to address
  41. $mail->addReplyTo('replyto@example.com', 'First Last');
  42. //Set who the message is to be sent to
  43. $mail->addAddress('whoto@example.com', 'John Doe');
  44. //Set the subject line
  45. $mail->Subject = 'PHPMailer GMail SMTP test';
  46. //Read an HTML message body from an external file, convert referenced images to embedded,
  47. //convert HTML into a basic plain-text alternative body
  48. $mail->msgHTML(file_get_contents('contents.html'), __DIR__);
  49. //Replace the plain text body with one created manually
  50. $mail->AltBody = 'This is a plain-text message body';
  51. //Attach an image file
  52. $mail->addAttachment('images/phpmailer_mini.png');
  53. //send the message, check for errors
  54. if (!$mail->send()) {
  55.     echo "Mailer Error: " . $mail->ErrorInfo;
  56. } else {
  57.     echo "Message sent!";
  58.     //Section 2: IMAP
  59.     //Uncomment these to save your message in the 'Sent Mail' folder.
  60.     #if (save_mail($mail)) {
  61.     #    echo "Message saved!";
  62.     #}
  63. }
  64. //Section 2: IMAP
  65. //IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
  66. //Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
  67. //You can use imap_getmailboxes($imapStream, '/imap/ssl', '*' ) to get a list of available folders or labels, this can
  68. //be useful if you are trying to get this working on a non-Gmail IMAP server.
  69. function save_mail($mail)
  70. {
  71.     //You can change 'Sent Mail' to any other folder or tag
  72.     $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
  73.     //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
  74.     $imapStream = imap_open($path, $mail->Username, $mail->Password);
  75.     $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
  76.     imap_close($imapStream);
  77.     return $result;
  78. }
  79. ?>
  80.  
  81. <!DOCTYPE html>
  82. <html>
  83.     <head>
  84.         <title>Testing Fetch</title>
  85.     </head>    
  86.     <body>
  87. Test
  88.  
  89.     </body>
  90. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top