Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <?php
  2. include 'Mail.php';
  3. include 'Mail/mime.php' ;
  4.  
  5. $from = "Robert Davis <mymail@gmail.com>";
  6. $to = "Sam Hill <receiver>";
  7. $subject = 'Test mime message with an attachment';
  8.  
  9. $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
  10.  
  11. $text = 'Text version of email';// text and html versions of email.
  12. $html = '<html><body>HTML version of email. <strong>This should be bold</strong></body> </html>';
  13.  
  14. $file = './sample.txt'; // attachment
  15. $crlf = "n";
  16.  
  17. $mime = new Mail_mime($crlf);
  18. $mime->setTXTBody($text);
  19. $mime->setHTMLBody($html);
  20. $mime->addAttachment($file, 'text/plain');
  21.  
  22. //do not ever try to call these lines in reverse order
  23. $body = $mime->get();
  24. $headers = $mime->headers($headers);
  25.  
  26. $host = "smtp.gmail.com";
  27. $username = "mymail";
  28. $password = "mypass";
  29.  
  30. $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true 'username' => $username,'password' => $password));
  31.  
  32. $mail = $smtp->send($to, $headers, $body);
  33.  
  34. if (PEAR::isError($mail)) {
  35. echo("<p>" . $mail->getMessage() . "</p>");
  36. }
  37. else {
  38. echo("<p>Message successfully sent!</p>");
  39. }
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement