Forum Moderators: coopster
I've got my contact form all setup but I'm new to HTML interacting with Email...
My goal is to set the print out at the bottom of the script to print <h2> before and after the name..
$msg .= "Name:".$HTTP_POST_VARS["name"]."\n";
However I haven't figured out how to get it to parse even in the browser! EEK! Anyway I also defintly can't figure out how to get it to parse in my email client when a person uses the form... feel free to use the form if you want btw...
<?
function check_len(&$check, $field, $max, &$err_field, $err="", $min, $min_err="")
{
if (strlen($field) > $max)
{
if ($err == "")
{
$err = $msg->err_maxlen($max);
}
$err_field = $err;
if ($check==true) $check = false;
}
if (strlen($field) < $min)
{
if ($min_err == "")
{
$min_err = $msg->err_minlen($min);
}
$err_field = $min_err;
if ($check==true) $check = false;
}
}function check_mail(&$check, $fld, &$error_field, $invalidchars="", $blanks="")
{
global $msg;
$expr = "^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z][a-z]+\$";
//echo "expr=" . $expr . "<br>";
if ((!$fld) ¦¦ ($fld=="") ¦¦ (!eregi($expr,$fld)))
{
if ($invalidchars > "")
{
$error_field = $invalidchars . "<br>\n";
} else {
$error_field = "invalid characters<br>\n";
}
if ($check==true) $check =false;
}
if (strrpos($fld,' ') > 0)
{
if ($blanks > "")
{
$error_field = $blanks . "<br>\n";
} else {
$error_field = "blanks in e-mail<br>\n";
}
if ($check==true) $check =false;
}
}
if (empty($HTTP_POST_VARS["name"])) $HTTP_POST_VARS["name"]="";
if (empty($err_name)) $err_name=" ";
if (empty($HTTP_POST_VARS["phone"])) $HTTP_POST_VARS["phone"]="";
if (empty($err_phone)) $err_phone=" ";
if (empty($HTTP_POST_VARS["email"])) $HTTP_POST_VARS["email"]="";
if (empty($err_email)) $err_email=" ";
if (empty($HTTP_POST_VARS["comments"])) $HTTP_POST_VARS["comments"]="";
if (empty($err_comments)) $err_comments=" ";
if (empty($HTTP_POST_VARS["preference"])) $HTTP_POST_VARS["preference"]="Phone,E-Mail";
if (empty($err_preference)) $err_preference=" ";
if (empty($HTTP_POST_VARS["street"])) $HTTP_POST_VARS["street"]="";
if (empty($err_street)) $err_street=" ";
if (empty($HTTP_POST_VARS["city"])) $HTTP_POST_VARS["city"]="";
if (empty($err_city)) $err_city=" ";
if (empty($HTTP_POST_VARS["state"])) $HTTP_POST_VARS["state"]="Yes,No";
if (empty($err_state)) $err_state=" ";
if (empty($HTTP_POST_VARS["zip"])) $HTTP_POST_VARS["zip"]="";
if (empty($err_zip)) $err_zip=" ";
if (empty($HTTP_POST_VARS["referral"])) $HTTP_POST_VARS["referral"]="";
if (empty($err_referral)) $err_referral=" ";
$checked = true;
if (isset($HTTP_POST_VARS["submit"]))
{
check_len($checked, $HTTP_POST_VARS["name"],32,$err_name,"Field too long! Maximum:32",1,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["phone"],15,$err_phone,"Field too long! Maximum:15",1,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["email"],80,$err_email,"Field too long! Maximum:80",0,"Field required! Minimum:1");
check_mail($checked, $HTTP_POST_VARS["email"], $err_email,"The e-mail contains invalid characters or is incomplete.", "The e-mail contains blanks.");
check_len($checked, $HTTP_POST_VARS["comments"],16384,$err_comments,"Field too long! Maximum:16384",1,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["preference"],8,$err_preference,"Field too long! Maximum:8",1,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["street"],32,$err_street,"Field too long! Maximum:32",0,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["city"],32,$err_city,"Field too long! Maximum:32",0,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["state"],32,$err_state,"Field too long! Maximum:32",1,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["zip"],10,$err_zip,"Field too long! Maximum:10",0,"Field required! Minimum:1");
check_len($checked, $HTTP_POST_VARS["referral"],32,$err_referral,"Field too long! Maximum:32",0,"Field required! Minimum:1");
}
if ( empty($HTTP_POST_VARS["submit"]) or (!$checked) )
{
?>
<form action="<? echo $GLOBALS["PHP_SELF"]?>" method="post"><table cellpadding="4" border="0">
<tr><td valign="top">Name:</td><td>
<input type="text" name="name" value="<? echo $HTTP_POST_VARS["name"]?>">
</td><td>
<? echo $err_name?>
</td></tr>
<tr><td valign="top">Phone:</td><td>
<input type="text" name="phone" value="<? echo $HTTP_POST_VARS["phone"]?>">
</td><td>
<? echo $err_phone?>
</td></tr>
<tr><td valign="top">E-Mail:</td><td>
<input type="text" name="email" value="<? echo $HTTP_POST_VARS["email"]?>">
</td><td>
<? echo $err_email?>
</td></tr>
<tr><td valign="top">Comments:</td><td>
<textarea name="comments"><? echo $HTTP_POST_VARS["comments"]?></textarea>
</td><td>
<? echo $err_comments?>
</td></tr>
<tr><td valign="top">Reply By:</td><td>
<select size="1" name="preference"><option value="Phone"<? if ($HTTP_POST_VARS["preference"]== 'Phone') echo ' SELECTED="SELECTED"'?>>Phone</option>
<option value="E-Mail"<? if ($HTTP_POST_VARS["preference"]== 'E-Mail') echo ' SELECTED="SELECTED"'?>>E-Mail</option>
</select>
</td><td>
<? echo $err_preference?>
</td></tr>
<tr><td valign="top">Street Address:</td><td>
<input type="text" name="street" value="<? echo $HTTP_POST_VARS["street"]?>">
</td><td>
<? echo $err_street?>
</td></tr>
<tr><td valign="top">City:</td><td>
<input type="text" name="city" value="<? echo $HTTP_POST_VARS["city"]?>">
</td><td>
<? echo $err_city?>
</td></tr>
<tr><td valign="top">Florida Resident?</td><td>
<select size="1" name="state"><option value="Yes"<? if ($HTTP_POST_VARS["state"]== 'Yes') echo ' SELECTED="SELECTED"'?>>Yes</option>
<option value="No"<? if ($HTTP_POST_VARS["state"]== 'No') echo ' SELECTED="SELECTED"'?>>No</option>
</select>
</td><td>
<? echo $err_state?>
</td></tr>
<tr><td valign="top">Zip Code:</td><td>
<input type="text" name="zip" value="<? echo $HTTP_POST_VARS["zip"]?>">
</td><td>
<? echo $err_zip?>
</td></tr>
<tr><td valign="top">Referred By:</td><td>
<input type="text" name="referral" value="<? echo $HTTP_POST_VARS["referral"]?>">
</td><td>
<? echo $err_referral?>
</td></tr>
<tr><td> </td><td><input type="submit" name="submit" value="Send"></td></tr>
</table></form>
<?
}
if (isset($HTTP_POST_VARS["submit"]) and ($checked) ) {
$msg = "You have mail ;-)\n";
$msg .= "Name:".$HTTP_POST_VARS["name"]."\n";
$msg .= "Phone=".$HTTP_POST_VARS["phone"]."\n";
$msg .= "E-Mail=".$HTTP_POST_VARS["email"]."\n";
$msg .= "Comments=".$HTTP_POST_VARS["comments"]."\n";
$msg .= "Reply By=".$HTTP_POST_VARS["preference"]."\n";
$msg .= "Street=".$HTTP_POST_VARS["street"]."\n";
$msg .= "City=".$HTTP_POST_VARS["city"]."\n";
$msg .= "Florida=".$HTTP_POST_VARS["state"]."\n";
$msg .= "Zip Code=".$HTTP_POST_VARS["zip"]."\n";
$msg .= "Referred By=".$HTTP_POST_VARS["referral"]."\n";
mail("someone@someplace.com","Business Inquiry",
$msg);
echo "e-mail has been sent to: someone@someplace.com<br>\n";
echo nl2br($msg) . "<br>\n";
}
?>
[edited by: jatar_k at 6:00 pm (utc) on Oct. 13, 2004]
[edit reason] removed urls and generalized emails [/edit]
Thanks for the tip... but it's still not rendering the HTML and the settings are the same as when my Yahoo mail was rendered...
One thing I noticed was that Yahoo used an iframe, however a political newsletter I subscribe to used an xbody tag...
So I'm really confused... I figure there is some kind of text/html context type but I figure this would be in the header of the email?