use_gmail.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // example on using PHPMailer with GMAIL
  3. include("class.phpmailer.php");
  4. include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
  5. $mail = new PHPMailer();
  6. $body = $mail->getFile('contents.html');
  7. $body = eregi_replace("[\]",'',$body);
  8. $mail->IsSMTP();
  9. $mail->SMTPAuth = true; // enable SMTP authentication
  10. $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
  11. $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
  12. $mail->Port = 465; // set the SMTP port
  13. $mail->Username = "yourname@gmail.com"; // GMAIL username
  14. $mail->Password = "password"; // GMAIL password
  15. $mail->From = "replyto@yourdomain.com";
  16. $mail->FromName = "Webmaster";
  17. $mail->Subject = "This is the subject";
  18. $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
  19. $mail->WordWrap = 50; // set word wrap
  20. $mail->MsgHTML($body);
  21. $mail->AddReplyTo("replyto@yourdomain.com","Webmaster");
  22. $mail->AddAttachment("/path/to/file.zip"); // attachment
  23. $mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
  24. $mail->AddAddress("username@domain.com","First Last");
  25. $mail->IsHTML(true); // send as HTML
  26. if(!$mail->Send()) {
  27. echo "Mailer Error: " . $mail->ErrorInfo;
  28. } else {
  29. echo "Message has been sent";
  30. }
  31. ?>