PDA

View Full Version : PHP FormMail Formatting Output


fwr1000
02-06-2007, 02:36 PM
I have a "Contact" php form using form mail and all is working great. However, the outputed (is that a word?) information on the email is difficult to read. I read somewhere once that one could format the e mail to make it easier to read. What is required to do this?

Thnx
Fred

davidj
02-06-2007, 03:52 PM
post ya code

email script please

fwr1000
02-06-2007, 04:23 PM
Page link is www.douglasvalley.net/contact_page.html

CODE


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Douglas Valley Contact Page</title>
<style type="text/css">
<!--
#wrapper {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
background-color: #911f43;
border: medium solid #FFFFFF;
}
body {
background-color: #911f43;
}
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
color: #FFFFFF;
text-decoration: none;
}
a:hover {
color: #911F43;
text-decoration: none;
background-color: #FFFFFF;
}
.submit {
color: #911F43;
background-color: #FFFFFF;
font-weight: normal;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=fal se,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidd en'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.g etMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:o;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</head>

<body>
<div id="wrapper">
<p align="center"><img src="Images/dv_logo_sm.jpg" alt="Douglas Valley Logo" width="400" height="200" /></p>
<p align="center">Please complete form below and then click on the Send Inquiry button at bottom.&nbsp; We will contact&nbsp; you promptly.</p>
<form action="http://www.douglasvalley.net/contact.php" "method="post" name="Contact Form" id="Contact Form" onsubmit="YY_checkform('Contact Form','first_name','#q','0','Please Complete First Name','Phone_No','#q','0','Please Complete Phone Number','E_Mail','#q','0','Please Complete E Mail Address');return document.MM_returnValue">
<table align="center" cellpadding="5" cellspacing="0" id="Form_Table">
<tr>
<td>First Name* </td>
<td><input name="first_name" type="text" id="first_name" size="30" /></td>
</tr>
<tr>
<td>Last Name* </td>
<td><input name="Last_Name" type="text" id="Last_Name" size="30" /></td>
</tr>
<tr>
<td><p>Street Address </p> </td>
<td><input name="Street_Address" type="text" id="Street_Address" size="45" /></td>
</tr>
<tr>
<td>City</td>
<td><input name="City" type="text" id="City" size="30" /></td>
</tr>
<tr>
<td>State</td>
<td><input name="State" type="text" id="State" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Zip Code </td>
<td><input name="Zip_Code" type="text" id="Zip_Code" size="9" maxlength="9" /></td>
</tr>
<tr>
<td>Phone Number* </td>
<td><input name="Phone_No" type="text" id="Phone_No" size="14" /></td>
</tr>
<tr>
<td>E-Mail*</td>
<td><input name="E_Mail" type="text" id="E_Mail" size="30" /></td>
</tr>
<tr>
<td>Best Time to Contact </td>
<td><select name="Best_Time" id="Best_Time">
<option>(Please Choose One)</option>
<option>Business Hours 8-5</option>
<option>Morning</option>
<option>Afternoon</option>
<option>Evening</option>
</select> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Please Enter Information Requested Below </td>
</tr>
<tr>
<td valign="top"><div ><font size="-1">* = Required </font></div></td>
<td><textarea name="Inquiry_Data" cols="50" rows="20" id="Inquiry_Data"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">
<input name="Submit" type="submit" class="submit" value="Send Inquiry" />
</div></td>
</tr>
</table>
</form>
<p><a href="index.html">&nbsp;&nbsp; Click here to quit and return to home page</a> </p>
</div>
</body>
</html>

davidj
02-06-2007, 05:28 PM
that was the form

can you post the PHP email script

fwr1000
02-06-2007, 08:50 PM
Sorry, here you go.



<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Web Site Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'judyc@douglasvalley.net';

// Where to redirect after form is processed.
$url = 'http://www.douglasvalley.net/thank_you.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

davidj
02-06-2007, 09:00 PM
please use this script to send a mail to me at

nirvanadesign[at]msn.com

fwr1000
02-06-2007, 09:11 PM
It's on it's way.

Fred

davidj
02-06-2007, 09:17 PM
if you were sending the mail as HTML then you would have control over font sizes etc but as this is sent as text then its a client side setting through the mail client

i have attached a screen dump of what the mail looks like to me in outlook

I dont see a problem really

fwr1000
02-06-2007, 09:25 PM
Interesting, when I tested it earlier using Outlook XP (2000), the input data was jammed to the left against the field names. I'll do some more testing (and remove you e mail address from the script) and let you know what I find.
thnx again
Fred

davidj
02-06-2007, 09:29 PM
feel free to use me

if you send any additional mails that you would like to test visually i will post them in this thread as a screen dumps

fwr1000
02-09-2007, 03:16 PM
What I fould out was the out put was viewed not on Outlook but on the web host's webmail. (Note it's Startlogic using Vdeck). For some reason it pushed the results to the left against the field name. I've since revised the form (using the Coffee Cup Form Builder) and the Vdeck reader the hosting company uses formats everything ok.