Abbi pazienza ma allora saresti contrario
anche a questo uso (insomma in tutti gli
esempi nel web + o - è riportato lo stesso uso).
Codice PHP:
<?php
class FileReader{
  private 
$file;
  private 
$fileDir='fileDir/';
  const 
FILE_DATA_ERROR=1;
  const 
EMAIL_DATA_ERROR=2;
  public function 
__construct($file){
    if(!
file_exists("{$this->fileDir}{$file}.php")){
      throw new 
Exception('File '.$file.' not found',self::FILE_DATA_ERROR);
    }
    
$this->file=$file;
  }
  public function 
getContent(){
    if(!
$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
      throw new 
Exception('Unable to read filecontents',self::FILE_DATA_ERROR);
    }
    return 
$content;
  }
  public function 
mailContent(){
    if(!@
mail('Recipient<user@domain.com>','HTML Page',$this->getContent())){
      throw new 
Exception('Unable to send by email file contents',self::EMAIL_DATA_ERROR);
    }
  }
}
try{
  
$fr=new FileReader('sample_file'); // potential error condition
  // email file content
  
$fr->mailContent(); // potential error condition 
  // echo file content
  
echo $fr->getContent(); // potential error condition
}
catch(
Exception $e){
  
// if error occurred when reading file data, stop program execution
  
if($e->getCode()==1){
    die(
$e->getMessage());
  }
  
// if error occurred when emailing file data, send error message to system logger
  
else if($e->getCode()==2){
    echo 
$e->getMessage().'
'
;
    
error_log($e->getMessage(),0);
  }
}



?>
Fammi sapere.