leo10
01-08-2009, 09:30 AM
I made a form to send emails with but i can't get it to make email clients understand theres html in the email
code:
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['email']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$to = $_REQUEST['to'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail(
"$to",
"Subject: $subject",
$message="<html><body>".$_POST['message_html']."</body></html>", "From: $email" );
echo "Thank you for using our mail form $name";
}
}
else
{//if "email" is not filled out, display the form
echo
"
<script language='javascript1.2'>
// attach the editor to the textarea with the identifier 'textarea1'.
WYSIWYG.attach('mailtext');
</script>
<form method='post' action=''>
Name: <input name='name' type='text' /><br /><br />
Email: <input name='email' type='text' /><br /><br />
To: <input name='to' type='text' /><br /><br />
Subject: <input name='subject' type='text' /><br /><br />
Message:<br />
<textarea id='mailtext' name='message_html' style='height: 170px; width: 475px;'>
</textarea>
<br />
<input type='submit' value='Send' />
</form>";
}
?>
code:
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['email']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$to = $_REQUEST['to'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail(
"$to",
"Subject: $subject",
$message="<html><body>".$_POST['message_html']."</body></html>", "From: $email" );
echo "Thank you for using our mail form $name";
}
}
else
{//if "email" is not filled out, display the form
echo
"
<script language='javascript1.2'>
// attach the editor to the textarea with the identifier 'textarea1'.
WYSIWYG.attach('mailtext');
</script>
<form method='post' action=''>
Name: <input name='name' type='text' /><br /><br />
Email: <input name='email' type='text' /><br /><br />
To: <input name='to' type='text' /><br /><br />
Subject: <input name='subject' type='text' /><br /><br />
Message:<br />
<textarea id='mailtext' name='message_html' style='height: 170px; width: 475px;'>
</textarea>
<br />
<input type='submit' value='Send' />
</form>";
}
?>