CMSimple Custom Mailform

This addon is actually a CMSimple script. To activate it an e-mail address has to be inserted under CMSimple Settings. This addon has been tested for CMSimple v.2.4 and v.2.9.

Installation

Copy the whole code and paste it into an empty CMSimple page below a proper H1 Heading. Use a simple offline text editor like editplus e.a. on your local machine. If you use an online editor like OEDIT or TinyMCE, the code will not work afterwards. After uploading of the content.htm file onto the server it should be possible to edit the code with the internal CMSimple editor OEDIT only. Other online text editors will destroy the php code.

CODE

<TEXTAREA style="WIDTH: 101.34%; HEIGHT: 275px" rows=14>
#CMSimple // Custom mailform for CMSimple version 2.4
$reciever='[email protected]';
$message="\n\nThis is an automatic generated mail.\n\nSincerely\nThe Webmaster";
$recievermessage="\n\nThis is an automatic generated mail.";
// Define your field names and add extra lines for select options
// Use _ for spaces
$fields=array('name','adress','zip','Define_your_own','email');
$select['adress']=array('none','elephant','cow','tiger');
$tx['mailform']['recieptnotsend']="Could not send reciept.";
// DO NOT CHANGE CODE BELOW!
function mtr($tk){if (is_array($GLOBALS['select'][$tk]))$t=select($tk); else $t='<input type="text" class="text" name="'.$tk.'" value="'.$GLOBALS[$tk].'">';
return '<tr><td>* '.ucfirst(preg_replace('/\_/',' ',$tk)).'</td><td>'.$t.'</td></tr>';}
function select($tk){$t='';foreach($GLOBALS['select'][$tk] as $i){$t.='<option value="'.$i.'"';
if($GLOBALS[$tk]==$i)$t.=' selected';
$t.='>'.$i.'</option>';} return '<select class="text" name="'.$tk.'">'.$t.'</select>';}
$t='';$mailbody='';
if($action=='send'){foreach($fields as $i){initvar($i);if($GLOBALS[$i]=='')$e.='<li>You need to write '.$i;else $mailbody.=$i.': '.$GLOBALS[$i]."\n";}if(!(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[_a-z0-9-]+)*(\.([a-z]{2,4}))+$",$email)))$e.='<li>'.$tx['error']['mustwritemail'].'.';else if($e==''){initvar('txtarea');$mailbody.=$txtarea;if(!(@mail($reciever,'Mailform from '.sv('SERVER_NAME'),$mailbody.$recievermessage,"From: ".$email."\r\n"."X-Remote: ".sv('REMOTE_ADDR')."\r\n")))$e.=tag('li').$tx['mailform']['notsend'];else {$t=tag('p').$tx['mailform']['send'].tag('/p/index.html');if(!(@mail($email,'Copy of mailform from '.sv('SERVER_NAME'),$mailbody.$message,"From: ".$reciever."\r\n"."X-Remote: ".sv('REMOTE_ADDR')."\r\n")))$e.='<li>'.$tx['mailform']['recieptnotsend'];}}}if($t==''||$e!=''){
$t='<form action="'.$sn.'" method="post"><input type="hidden" name="selected" value="'.$u[$s].'"><input type="hidden" name="action" value="send"><table cellpadding="5" cellspacing="0" border="0">';
foreach($fields as $field)$t.=mtr($field);
$t.='<tr><td colspan="2">Message:<br><t'.'extarea rows="6" cols="40" name="t'.'xtarea"></t'.'extarea></td></tr>';
$t.='</table><p><input type="submit" class="submit" value="'.$tx['mailform']['sendbutton'].'"></p></form>'; }
$output=preg_replace('/lttextareatextareagt/is/index.html',$t,$c[$s]);#
</TEXTAREA>

The code should generate following outcome:

Custom Mail
(click image to enlarge)

back to addons

see also: advanced_form

addons/custom_mailform.txt · Last modified: 2008/05/20 16:35 by till