1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
<?php
/*
* Copyright (C) 2003-2005 Polytechnique.org
* http://opensource.polytechnique.org/
*
* This program 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 program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once 'Plugin/Filter.php';
require_once 'diogenes/diogenes.hermes.inc.php';
/** The MailForm plugin allows you to insert a form to send
* an e-mail to a fixed recipient.
*
* To make use of this plugin, insert {MailForm}in your page
* where the mail form should appear.
*/
class MailForm extends Diogenes_Plugin_Filter
{
/** Plugin name */
var $name = "MailForm";
/** Plugin description */
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.";
/** Plugin parameters */
var $params = array('email' => '', 'title' => '', 'subject_tag' => '[web form] ');
/** Show an instance of the MailForm plugin.
*/
function show()
{
global $page;
// get params
$to_email = $this->params['email'];
$form_title = $this->params['title'];
if (!isvalid_email($to_email)) {
return '<p>You must specify a valid e-mail in the "email" parameter to make use of the MailForm plugin.<p>';
}
// get input
$action = clean_request('action');
$from = clean_request('from');
$refer = strip_request('refer');
if (!$refer)
$refer = $_SERVER['HTTP_REFERER'];
$message = strip_request('message');
$subject = strip_request('subject');
$showform=0;
$output = '';
switch($action) {
case "mail":
if ((!$subject)||(!$message)||(!$from)) {
$output .= '<p align="center"><strong>Missing fields !</strong></p>';
$showform=1;
break;
}
if (!isvalid_email($from)) {
$output .= '<p align="center"><strong>Invalid email address !</strong></p>';
$showform=1;
break;
}
$mymail = new HermesMailer();
$mymail->setFrom($from);
$mymail->setSubject($this->params['subject_tag'].$subject);
$mymail->addTo($to_email);
$mymail->setTxtBody($message);
$mymail->send();
$output .= '<p align="center"><strong>Message sent !</strong></p>';
if ($refer!="") {
$output .= '<p align="center">To return to referring web page click <a href="'.$refer.'">here</a></p>';
}
break;
default:
$showform=1;
}
if ($showform) {
$output .=
'<br/>
<form action="'.$page->script_uri().'" method="post">
<table class="light">
<tr>
<th colspan="2">'.$form_title.'</a></th>
</tr>
<tr>
<td>'.__("from").'</td>
<td><input type="text" name="from" size="68" value="'.$from.'" /></td>
</tr>
<tr>
<td>'.__("subject").'</td>
<td><input type="text" name="subject" size="68" value="'.$subject.'" /></td>
</tr>
<tr>
<td>'.__("message").'</td>
<td><textarea name="message" rows="10" cols="70">'.$message.'</textarea></td>
</tr>
<tr>
<td> </td>
<td>
<input type="hidden" name="action" value="mail" />
<input type="hidden" name="refer" value="'.$refer.'" />
<input type="submit" value="'.__("Send").'"/>
</td>
</tr>
</table>
</form>';
}
return $output;
}
}
?>
|