PHP Classes
Icontem

File: PostNewMail.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Frank Rust  >  Parse Mail  >  PostNewMail.php  
File: PostNewMail.php
Role: Example script
Content type: text/plain
Description: Part one of Example
Class: Parse Mail
Parse the headers and bodies of e-mail messages
 

Contents

Class file image Download
<?php
    
// Very simple example:
    // receive an email file on stdin and post that file to an url
    // (e.g. on a Unix-like server create an entry in /etc/aliases:
    // phpmail: |PostNewMail.php
    // PostNewMail.php should be executable and have the 
    // #!/path/to/console-php -q 
    // in the first line. Don't forget to allow
    // the execution of this program to smrsh)
    //
    // Version 0.1, 2005/03/13
    // Copyright (c) Frank Rust, TU Braunschweig (f.rust@tu-bs.de)
    //
    // This code is free software; you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation; either version 2 of the License, or
    // (at your option) any later version.
    // 
    // This code is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    // 
    // Since this is a very short Program the GNU General Public License
    // is not included. Please find it on the website of the Open Software
    // Foundation at
    //     http://www.fsf.org/licensing/licenses/lgpl.txt
    // or write to the Free Software Foundation, Inc., 59 Temple Place, 
    // Suite 330, Boston, MA  02111-1307  USA
    

    
    // create temporary file to store the mail
    
$tmpnam=tempnam("/tmp","MAIL");
    
$tmpfile=fopen($tmpnam,"w");

    
// read mail from stdin
    
$input=fopen("php://stdin","r");
    
    
// read complete mail and write it to tmpfile
    
while (!feof($input)) {
        
$line fgets($input,4096);
        
fwrite($tmpfile,$line);
    }
    
fclose($input); 
    
fclose($tmpfile);

    
// use cURL to post the file to the Websystem
    
$postvars=array("postfile" => "@".$tmpnam );
    
    
$URL="http://www.mywebhost.org/getEmail.php";
    
    
$ch=curl_init($URL);
    
$user_agent="Franks Email POSTer";
    
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    
curl_setopt ($chCURLOPT_USERAGENT$user_agent);
    
curl_setopt($chCURLOPT_POST1);
    
curl_setopt($chCURLOPT_VERBOSE0); // 1 for debugging
    
curl_setopt($chCURLOPT_POSTFIELDS$postvars);
    
curl_setopt($chCURLOPT_RETURNTRANSFER1);
    
$x=curl_exec($ch);
    
$info=curl_getinfo($ch);
    
curl_close($ch);

    
//for debugging the console program: 
    
echo $xprint_r($info);

    
// cleanup
    
unlink($tmpnam);    
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products