Advertisement
AlanVncs

PHPMailer GMail

Feb 5th, 2017
1,735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. <?php
  2.  
  3. // First of all, unlock Gmail -> https://www.youtube.com/watch?v=o_lkI_NAbo0
  4.  
  5. /**
  6.  * This example shows settings to use when sending via Google's Gmail servers.
  7.  */
  8. //SMTP needs accurate times, and the PHP time zone MUST be set
  9. //This should be done in your php.ini, but this is how to do it if you don't have access to that
  10. date_default_timezone_set('Etc/UTC');
  11.  
  12. require '../PHPMailerAutoload.php';
  13.  
  14. $mail = new PHPMailer;
  15.  
  16. $mail->isSMTP();
  17.  
  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.  
  24. //Ask for HTML-friendly debug output
  25. $mail->Debugoutput = 'html';
  26.  
  27. //Set the hostname of the mail server
  28. // use $mail->Host = gethostbyname('smtp.gmail.com');
  29. // if your network does not support SMTP over IPv6
  30. $mail->Host = 'smtp.gmail.com';
  31.  
  32. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  33. $mail->Port = 587;
  34.  
  35. //Set the encryption system to use - ssl (deprecated) or tls
  36. $mail->SMTPSecure = 'tls';
  37.  
  38. //Whether to use SMTP authentication
  39. $mail->SMTPAuth = true;
  40.  
  41. //Username to use for SMTP authentication - use full email address for gmail
  42. $mail->Username = "smartlight0117@gmail.com";
  43. //Password to use for SMTP authentication
  44. $mail->Password = "yourpassword";
  45.  
  46. //Set who the message is to be sent from
  47. $mail->setFrom('smartlight0117@gmail.com', 'Smart Light');
  48. //Set an alternative reply-to address
  49. $mail->addReplyTo('replytoanotheremail@example.com', 'Another email');
  50. //Set who the message is to be sent to
  51. $mail->addAddress($gmail, 'His Name');
  52.  
  53. //Set the subject line
  54. $mail->Subject = 'Password Recovery';
  55.  
  56. //Read an HTML message body from an external file, convert referenced images to embedded,
  57. //convert HTML into a basic plain-text alternative body
  58. //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  59.  
  60. // Normal text plain
  61. $mail->msgHTML("Your new password is '999999999'");
  62.  
  63. //Replace the plain text body with one created manually
  64. //$mail->AltBody = 'I've no idea what is it';
  65.  
  66. //Attach an image file
  67. //$mail->addAttachment('images/phpmailer_mini.png');
  68. //send the message, check for errors
  69. if (!$mail->send()) {
  70.     echo "Mailer Error: " . $mail->ErrorInfo;
  71. } else {
  72.     echo "Message sent!";
  73. }
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement