Advertisement
abhijit5893

Sending mail from localhost(WAMP) using SMTP Protocol and PH

Feb 2nd, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. require_once 'Mail.php';
  3. include('Mail/mime.php');
  4.  
  5. $from = 'your gmail id';
  6. $to = 'your addr';
  7. $subject = 'Hi!';
  8. $body = "Well dude, Mail functionality is working isnt it :P.<br/><br/>Now with Attachments";
  9. $host = 'ssl://smtp.gmail.com';
  10. $username = 'your gmail id'; // same as $from
  11. $password = 'your password';
  12.  
  13. $headers = array('From' => $from,
  14.     'To' => $to,
  15.     'Subject' => $subject
  16. );
  17.  
  18. $mime = new Mail_Mime("\n");
  19. $mime->setHTMLBody($body);
  20. $mime->addAttachment("a picture or any other attachment link");
  21.  
  22. $body = $mime->get();
  23. $headers = $mime->headers($headers);
  24.  
  25. $email = Mail::factory('smtp',
  26.     array('host' => $host,
  27.         'auth' => true,
  28.         'username' => $username,
  29.         'password' => $password,
  30.         'port' => 465
  31.     )
  32. );
  33.  
  34. $result = $email->send($to, $headers, $body);
  35.  
  36. if(PEAR::isError($result))
  37.     echo 'Error occurred: ' . $result->getMessage();
  38. else
  39.     echo 'Email sent.';
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement