Posted By

wnasich on 03/26/11


Tagged

php mail google gmail


Versions (?)

Send email using GMail SMTP server from PHP page


 / Published in: PHP
 

URL: http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page

  1. <?php
  2.  
  3. require_once "Mail.php";
  4.  
  5. $from = "<from.gmail.com>";
  6. $to = "<to.yahoo.com>";
  7. $subject = "Hi!";
  8. $body = "Hi,\n\nHow are you?";
  9.  
  10. $host = "ssl://smtp.gmail.com";
  11. $port = "465";
  12. $username = "<myaccount.gmail.com>";
  13. $password = "password";
  14.  
  15. $headers = array ('From' => $from,
  16. 'To' => $to,
  17. 'Subject' => $subject);
  18. $smtp = Mail::factory('smtp',
  19. array ('host' => $host,
  20. 'port' => $port,
  21. 'auth' => true,
  22. 'username' => $username,
  23. 'password' => $password));
  24.  
  25. $mail = $smtp->send($to, $headers, $body);
  26.  
  27. if (PEAR::isError($mail)) {
  28. echo("<p>" . $mail->getMessage() . "</p>");
  29. } else {
  30. echo("<p>Message successfully sent!</p>");
  31. }
  32.  
  33. ?> <!-- end of php tag-->

Report this snippet  

You need to login to post a comment.