home *** CD-ROM | disk | FTP | other *** search
/ 66-211-214-51.static.velocity.net / 66-211-214-51.static.velocity.net.tar / 66-211-214-51.static.velocity.net / OPMail / pearMail.php < prev    next >
PHP Script  |  2011-03-07  |  2KB  |  73 lines

  1. <?php
  2. require_once "Mail.php"; // PEAR Mail package
  3. require_once ('Mail/mime.php'); // PEAR Mail_Mime packge
  4.  
  5.  
  6. $myFile = "MailData.txt"; //file to read from
  7. $fh = fopen($myFile, 'r'); //open file for reading
  8. $host = trim(fgets($fh)); //gets email server
  9. $port = trim(fgets($fh)); //gets email server port
  10. $username = trim(fgets($fh)); //gets user name for email
  11. $password = trim(fgets($fh)); //gets password for email
  12. $from = trim(fgets($fh)); //gets FROM
  13. $to = trim(fgets($fh)); //gets TO
  14. $subject = trim(fgets($fh)); //gets SUBJECT
  15. $attachmentName = trim(fgets($fh)); //gets ATTACHMENT NAME
  16. $attachPath = trim(fgets($fh)); //gets PATH TO ATTACHMENT
  17. $body = "";
  18. while(!feof($fh))
  19.   {
  20.     $body .= fgets($fh);
  21.   }
  22. fclose($fh); //Close the File
  23. $attachmentFull = "";
  24. $attachmentFull .= $attachPath;
  25. $attachmentFull .= $attachmentName;
  26.  
  27.  
  28. //Local Testing variables
  29. /*
  30. $host = "smtp.aol.com"; //gets email server
  31. $port = 587; //gets email server port
  32. $username = 'mateomarriotti'; //gets user name for email
  33. $password = 'gunho'; //gets password for email
  34. $from = "Matt <mateomarriotti@aol.com>"; //gets FROM
  35. $to = "Matt <mateomarriotti@aol.com>"; //gets TO
  36. $subject ='Test mime message with an attachment'; //gets SUBJECT
  37. $attachmentName = 'sample.txt'; // attachment
  38. $attachPath = "./"; //gets PATH TO ATTACHMENT
  39. $body = "This is a test body for the email";
  40. */
  41.  
  42. $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
  43.  
  44. $text = $body;// text and html versions of email.
  45. $html = $body;
  46. //$html = '<html><body>HTML version of email. <strong>This should be bold</strong></body></html>';
  47.  
  48. $crlf = "\n";
  49.  
  50. $mime = new Mail_mime($crlf);
  51. $mime->setTXTBody($text);
  52. $mime->setHTMLBody($html);
  53. //$mime->addAttachment($attachmentName, 'text/plain');
  54. $mime->addAttachment($attachmentFull, 'text/plain');
  55.  
  56. //do not ever try to call these lines in reverse order
  57. $body = $mime->get();
  58. $headers = $mime->headers($headers);
  59.  
  60.  
  61. $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true,
  62.  'username' => $username,'password' => $password));
  63.  
  64. $mail = $smtp->send($to, $headers, $body);
  65.  
  66. if (PEAR::isError($mail)) {
  67.   echo("<p>" . $mail->getMessage() . "</p>");
  68. }
  69. else {
  70.   echo("<p>Message successfully sent!</p>");
  71. }
  72. ?>
  73.