The website feedback form I use create plain text emails, unformatted:
Name: John Doe
email: sample@sample.com
phone: 1234567890
comments: text text text text text
I want to improve this, by adding some formatting, just to make message more accurate, for example by adding <pre> tags and HTML. How to make this correctly in this code?
Below is PHP code:
Name: John Doe
email: sample@sample.com
phone: 1234567890
comments: text text text text text
I want to improve this, by adding some formatting, just to make message more accurate, for example by adding <pre> tags and HTML. How to make this correctly in this code?
Below is PHP code:
Code:
<?
if (!$_POST){
$return_from_module = draw_forma();
} else {
$error = check_data();
if ($error){
$return_from_module = draw_forma($error,$_POST);
} else {
$return_from_module = draw_success();
}
}
function draw_success(){
$body ="";
foreach($_POST as $field=>$value)
{
if($field!="submit") $body .="$field: $value\r\n";
}
if(mail ("info@website.com",'from WEBsite sample.com',$body,"From:website"))
return 'Thank You!';
}
function check_data(){
$error = '';
$error_mark = 'style="color:red"';
if (!$_POST["comments"])$error['comments'] = $error_mark;
if (!isset($_POST["email"]) OR (!preg_match('/\b(?:mailto:)?([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,7})\b/i', $_POST["email"]))) { $error['email'] = $error_mark; }
if (!$_POST["Name"]) $error['Name'] = $error_mark;
if (!$_POST["phone"]) $error['phone'] = $error_mark;
return $error;
}
function draw_forma($error=null,$POST=null){
$html='
<form method=post action="">
<style>
#form-table TD {vertical-align:top;padding-top:5px}
.zvezda {color:red}
</style>
#INS:message:name:text_above_form#<br><br>
<table cellspacing=0 border="0">
<tr>
<td valign=top>
<table border=0 id=form-table>
<tr>
<td '.@$error["Name"].'>#ins:message:name:vards#<span class=zvezda>*</span></td>
<td><input type="text" class=input value="'.$POST["Name"].'" name="Name" size=35></td>
</tr>
<tr>
<td '.@$error["email"].'>#ins:message:name:email#<span class=zvezda>*</span></td>
<td><input type="text" class=input value="'.$POST["email"].'" name="email" size=35></td>
</tr>
<tr>
<td '.@$error["phone"].'>#ins:message:name:phone#<span class=zvezda>*</span></td>
<td><input type="text" class=input value="'.$POST["phone"].'" name="phone" size=35></td>
</tr>
<tr>
<td '.@$error["comments"].'>#ins:message:name:Enquiry#<span class=zvezda>*</span></td>
<td><textarea name="comments" cols=42 rows=5>'.$POST["comments"].'</textarea></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign=top align=center>
<input type="submit" value=" Send form " name="submit">
</td>
</tr>
</table>
#INS:message:name:form#
</form>
';
return $html;
}
?>