ayand04

mailing

Mar 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.10 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Ayan Dey
  5.  * Date: 26-02-2018
  6.  * Time: 14:52
  7.  */
  8. use PHPMailer\PHPMailer\PHPMailer;
  9. use PHPMailer\PHPMailer\Exception;
  10.  
  11. require 'vendor/autoload.php';
  12.  
  13. //Create a new PHPMailer instance
  14. $mail = new PHPMailer();
  15.  
  16. //Tell PHPMailer to use SMTP
  17. $mail->isSMTP();
  18.  
  19. //Enable SMTP debugging
  20. // 0 = off (for production use)
  21. // 1 = client messages
  22. // 2 = client and server messages
  23. $mail->SMTPDebug = 2;
  24.  
  25. //Set the hostname of the mail server
  26. $mail->Host = 'a2plcpnl0347.prod.iad2.secureserver.net';
  27.  
  28. // use
  29. // $mail->Host = gethostbyname('smtp.gmail.com');
  30. // if your network does not support SMTP over IPv6
  31. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  32. $mail->Port = 465;
  33.  
  34. //Set the encryption system to use - ssl (deprecated) or tls
  35. $mail->SMTPSecure = 'tls';
  36.  
  37. //Whether to use SMTP authentication
  38. $mail->SMTPAuth = true;
  39.  
  40. //Username to use for SMTP authentication - use full email address for gmail
  41. $mail->Username = "no-reply@leesnap.com";
  42.  
  43. //Password to use for SMTP authentication
  44. $mail->Password = "1Wdr~)UP1}.;";
  45.  
  46. //Set who the message is to be sent from
  47. $mail->setFrom('no-reply@leesnap.com', 'Test mail');
  48.  
  49. //Set an alternative reply-to address
  50. $mail->addReplyTo('no-reply@leesnap.com', 'Test mail');
  51.  
  52. //Set who the message is to be sent to
  53. $mail->addAddress('ayand04@gmail.com', 'Ayan Dey');
  54.  
  55. //Set the subject line
  56. $mail->Subject = 'PHPMailer GMail SMTP test';
  57.  
  58. $mail->Body = 'This is the mail body';
  59.  
  60. //Read an HTML message body from an external file, convert referenced images to embedded,
  61. //convert HTML into a basic plain-text alternative body
  62. //$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
  63.  
  64. //Replace the plain text body with one created manually
  65. //$mail->AltBody = 'This is a plain-text message body';
  66.  
  67. //Attach an image file
  68. //$mail->addAttachment('images/phpmailer_mini.png');
  69.  
  70. //send the message, check for errors
  71. if (!$mail->send()) {
  72.     echo "Mailer Error: " . $mail->ErrorInfo;
  73. } else {
  74.     echo "Message sent!";
  75.     //Section 2: IMAP
  76.     //Uncomment these to save your message in the 'Sent Mail' folder.
  77.     #if (save_mail($mail)) {
  78.    #    echo "Message saved!";
  79.    #}
  80. }
  81.  
  82.  
  83. //Section 2: IMAP
  84. //IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
  85. //Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
  86. //You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
  87. //be useful if you are trying to get this working on a non-Gmail IMAP server.
  88. /*function save_mail($mail)
  89. {
  90.     //You can change 'Sent Mail' to any other folder or tag
  91.     $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
  92.     //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
  93.     $imapStream = imap_open($path, $mail->Username, $mail->Password);
  94.     $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
  95.     imap_close($imapStream);
  96.     return $result;
  97. }*/
Add Comment
Please, Sign In to add comment