Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2. /**
  3.  * This example shows settings to use when sending via Google's Gmail servers.
  4.  */
  5.  
  6. //SMTP needs accurate times, and the PHP time zone MUST be set
  7. //This should be done in your php.ini, but this is how to do it if you don't have access to that
  8. date_default_timezone_set('Etc/UTC');
  9.  
  10. require 'phpmailer/PHPMailerAutoload.php';
  11.  
  12. //Create a new PHPMailer instance
  13. $mail = new PHPMailer;
  14.  
  15. //Tell PHPMailer to use SMTP
  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. $mail->Host = 'smtp.gmail.com';
  29. // use
  30. // $mail->Host = gethostbyname('smtp.gmail.com');
  31. // if your network does not support SMTP over IPv6
  32.  
  33. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  34. $mail->Port = 587;
  35.  
  36. //Set the encryption system to use - ssl (deprecated) or tls
  37. $mail->SMTPSecure = 'tls';
  38.  
  39. //Whether to use SMTP authentication
  40. $mail->SMTPAuth = true;
  41.  
  42. //Username to use for SMTP authentication - use full email address for gmail
  43. $mail->Username = "ramadhanfikar.rf@gmail.com";
  44.  
  45. //Password to use for SMTP authentication
  46. $mail->Password = "password";
  47.  
  48. //Set who the message is to be sent from
  49. $mail->setFrom('ramadhanfikar.rf@gmail.com', 'First Last');
  50.  
  51. //Set an alternative reply-to address
  52. //$mail->addReplyTo('replyto@example.com', 'First Last');
  53.  
  54. //Set who the message is to be sent to
  55. $mail->addAddress('nandinifera@gmail.com', 'John Doe');
  56.  
  57. //Set the subject line
  58. $mail->Subject = 'PHPMailer GMail SMTP test';
  59. $mail->Body ='oke';
  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.  
  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('phpmailer/examples/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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement