Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. <?php
  2. require '/PHPMailer_5.2.4/class.phpmailer.php';
  3.  
  4. $mail = new PHPMailer;
  5.  
  6. $mail->IsSMTP(); // Set mailer to use SMTP
  7. $mail->Host = 'smtp.gmail.com'; // Specify main and backup server
  8. $mail->SMTPAuth = true; // Enable SMTP authentication
  9. $mail->Username = 'hehe@gmail.com'; // SMTP username
  10. $mail->Password = 'xxx'; // SMTP password
  11. $mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
  12. $mail->Port = 465;
  13.  
  14. $mail->From = 'hehe@gmail.com';
  15. $mail->FromName = 'Mailer';
  16. $mail->AddAddress('hehe@gmail.com'); // Add a recipient
  17.  
  18. $mail->WordWrap = 50; // Set word wrap to 50 characters
  19. $mail->IsHTML(true); // Set email format to HTML
  20.  
  21. $mail->Subject = 'Here is the subject';
  22. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  23. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  24.  
  25. if(!$mail->Send()) {
  26. echo 'Message could not be sent.';
  27. echo 'Mailer Error: ' . $mail->ErrorInfo;
  28. exit;
  29. }
  30.  
  31. echo 'Message has been sent';
  32.  
  33. <?php
  34. include "PHPMailer_5.2.4/class.phpmailer.php"; // include the class name
  35. $mail = new PHPMailer(); // create a new object
  36. $mail->IsSMTP(); // enable SMTP
  37. $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  38. $mail->SMTPAuth = true; // authentication enabled
  39. $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  40. $mail->Host = "smtp.gmail.com";
  41. $mail->Port = 465; // or 587
  42. $mail->IsHTML(true);
  43. $mail->Username = "gmailusername@gmail.com";
  44. $mail->Password = "**********";
  45. $mail->SetFrom("anyemail@gmail.com");
  46. $mail->Subject = "Here is the subject";
  47. $mail->Body = "This is the HTML message body <b>in bold!</b>";
  48. if(!$mail->Send()){
  49. echo "Mailer Error: " . $mail->ErrorInfo;
  50. }
  51. else{
  52. echo "Message has been sent";
  53. }
  54. ?>
  55.  
  56. //Create a new PHPMailer instance
  57. $mail = new PHPMailer;
  58. //Tell PHPMailer to use SMTP
  59. $mail->isSMTP();
  60. //Enable SMTP debugging
  61. // 0 = off (for production use)
  62. // 1 = client messages
  63. // 2 = client and server messages
  64. $mail->SMTPDebug = 2;
  65. //Ask for HTML-friendly debug output
  66. $mail->Debugoutput = 'html';
  67. //Set the hostname of the mail server
  68. $mail->Host = 'smtp.gmail.com';
  69. // use
  70. // $mail->Host = gethostbyname('smtp.gmail.com');
  71. // if your network does not support SMTP over IPv6
  72. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  73. $mail->Port = 587;
  74. //Set the encryption system to use - ssl (deprecated) or tls
  75. $mail->SMTPSecure = 'tls';
  76. //Whether to use SMTP authentication
  77. $mail->SMTPAuth = true;
  78. //Username to use for SMTP authentication - use full email address for gmail
  79. $mail->Username = "username@gmail.com";
  80. //Password to use for SMTP authentication
  81. $mail->Password = "yourpassword";
  82. //Set who the message is to be sent from
  83. $mail->setFrom('from@example.com', 'First Last');
  84. //Set an alternative reply-to address
  85. $mail->addReplyTo('replyto@example.com', 'First Last');
  86. //Set who the message is to be sent to
  87. $mail->addAddress('whoto@example.com', 'John Doe');
  88. //Set the subject line
  89. $mail->Subject = 'PHPMailer GMail SMTP test';
  90. //Read an HTML message body from an external file, convert referenced images to embedded,
  91. //convert HTML into a basic plain-text alternative body
  92. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  93. //Replace the plain text body with one created manually
  94. $mail->AltBody = 'This is a plain-text message body';
  95. //send the message, check for errors
  96. if (!$mail->send()) {
  97. echo "Mailer Error: " . $mail->ErrorInfo;
  98. } else {
  99. echo "Message sent!";
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement