MailForm.php

00001 <?php 
00002 /*
00003  * Copyright (C) 2003-2005 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 require_once 'Plugin/Filter.php';
00022 require_once 'diogenes/diogenes.hermes.inc.php';
00023 
00030 class MailForm extends Diogenes_Plugin_Filter
00031 {  
00033   var $name = "MailForm";
00034   
00036   var $description = "This plugin allows you to insert a form to send an e-mail to a fixed recipient. To make use of this plugin, insert <b>{MailForm}</b> in your page where the mail form should appear.";
00037   
00039   var $params = array('email' => '', 'title' => '', 'subject_tag' => '[web form] ');
00040 
00043   function show()
00044   {
00045     global $page;
00046 
00047     // get params
00048     $to_email = $this->params['email'];
00049     $form_title = $this->params['title'];
00050     
00051     if (!isvalid_email($to_email)) {
00052       return '<p>You must specify a valid e-mail in the "email" parameter to make use of the MailForm plugin.<p>';
00053     }
00054         
00055     // get input
00056     $action = clean_request('action');
00057     $from = clean_request('from');
00058     
00059     $refer = strip_request('refer');
00060     if (!$refer) 
00061       $refer = $_SERVER['HTTP_REFERER'];
00062     $message = strip_request('message');
00063     $subject = strip_request('subject');
00064     
00065     $showform=0;
00066     $output = '';
00067     switch($action) {
00068     case "mail":
00069       if ((!$subject)||(!$message)||(!$from)) {
00070         $output .= '<p align="center"><strong>Missing fields !</strong></p>';
00071         $showform=1;
00072         break;
00073       }
00074     
00075       if (!isvalid_email($from)) {
00076         $output .= '<p align="center"><strong>Invalid email address !</strong></p>';
00077         $showform=1;
00078         break;
00079       }
00080       
00081       $mymail = new HermesMailer();
00082       $mymail->setFrom($from);
00083       $mymail->setSubject($this->params['subject_tag'].$subject);
00084       $mymail->addTo($to_email);
00085       $mymail->setTxtBody($message);
00086       $mymail->send();
00087     
00088       $output .= '<p align="center"><strong>Message sent !</strong></p>';
00089       if ($refer!="") {
00090         $output .= '<p align="center">To return to referring web page click <a href="'.$refer.'">here</a></p>';
00091       }
00092       break;
00093     default:
00094       $showform=1;
00095     }
00096         
00097     if ($showform) {
00098       $output .=
00099     '<br/>
00100     
00101     <form action="'.$page->script_uri().'" method="post">
00102     
00103     <table class="light">
00104       <tr>
00105         <th colspan="2">'.$form_title.'</a></th>
00106       </tr>
00107       <tr>
00108         <td>'.__("from").'</td>
00109         <td><input type="text" name="from" size="68" value="'.$from.'" /></td>
00110       </tr>
00111       <tr>
00112         <td>'.__("subject").'</td>
00113         <td><input type="text" name="subject" size="68" value="'.$subject.'" /></td>
00114       </tr>
00115       <tr>
00116         <td>'.__("message").'</td>
00117         <td><textarea name="message" rows="10" cols="70">'.$message.'</textarea></td>
00118       </tr>
00119       <tr>
00120         <td>&nbsp;</td>
00121         <td>
00122           <input type="hidden" name="action" value="mail" />
00123           <input type="hidden" name="refer" value="'.$refer.'" />
00124           <input type="submit" value="'.__("Send").'"/>
00125         </td>
00126       </tr>
00127     </table>
00128     
00129     </form>';
00130     }
00131     return $output;
00132   }
00133 }
00134 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1