I have the follwing form which is being populated via autosuggest from a database
<table class="table table-striped" id="itemsTable">
<thead>
<tr>
<th></th>
<th>Item Code</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr class="item-row">
<td></td>
<form id="itemsForm" action="services/processOrder.php" method="post">
<td><input type="text" name="itemCode[]" value="" class="input-medium" id="itemCode"
tabindex="1"/>
</td>
<td><input type="text" name="itemDesc[]" value="" class="input-large" id="itemDesc"
readonly="readonly"/></td>
<td><input type="text" name="itemQty[]" value="" class="input-mini" id="itemQty" tabindex="2"/>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span>
<input
name="itemPrice[]"
class=" input-small"
id="itemPrice"
type="text"></div>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span><input
name="itemLineTotal[]" class=" input-small" id="itemLineTotal" type="text"
readonly="readonly"></div>
</td>
</tr>
</tbody>
</table>
and here is the php query for the autosuggest:
<?php
require_once('db_connection.php');
$return_arr = array();
$param = $_GET["term"];
$query = "SELECT field_id_5, exp_weblog_titles.title, field_id_57
FROM exp_weblog_data, exp_weblog_titles
WHERE exp_weblog_titles.entry_id = exp_weblog_data.entry_id AND field_id_5
LIKE '%". $param ."%'
LIMIT 10";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
/* Retrieve and store in array the results of the query.*/
while ($row = $result->fetch_assoc()) {
$row_array['jItemCode'] = $row['field_id_5'];
$row_array['jItemDesc'] = $row['title'];
$row_array['jItemPrice'] = $row['field_id_57'];
//$row_array['jItemWholesale'] = $row['itemWholesale'];
//$row_array['jItemRetail'] = $row['itemRetail'];
// $row_array['jQtyOnHand'] = $row['qtyOnHand'];
array_push( $return_arr, $row_array );
}
$result->free_result();
$mysqli->close();
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
Finally here is the php for send the form as an email:
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_REQUEST['repName'] . ">\r\n";
$to = 'dominic.mcafee#pmcnttyyre.com';
$subject = "Web Contact Data";
$fields = array();
$fields{"itemCode[]"} = "Code";
$fields{"itemDesc[]"} = "Description";
$fields{"itemPrice[]"} = "Price";
$body = "We have received the following information:\n\n";
foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: noreply#example.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
$send = mail($to, $subject, $body);
if($send){
header( "Location:index.php" );
} else {
print "We encountered an error sending your mail, please try again";
}
?>
All I get in the email is "We have recieved the following information:
Code:
Description:
Price:
"
Please can someone help me out. Where am I going wrong. I know Im close and the problem lies somewhere in referencing the array of data that is in the form.
Hard to say from code, but main reason is that $_REQUEST[$a] is empty. So try to echo whole $_REQUEST right after submitting your form for better debugging.
Also I dont see submit button and also end of the form tag - it could be bug too.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am trying to execute "Tell a friend" php script, but that is not sending any emails, not to admin, friends, sender. Other emails on same server working fine.
I don't understand why this is not working, as other emails pages like contact us, registration (which send confimation email) all working on same server, please help me..
Html Code:
<table>
<tr>
<td>
<span>Complete the details below to send this link to a friend:</span>
<?php
$refurl = $_SERVER['HTTP_REFERER'];?>
<span><? print $refurl;?></span>
<form name="tellafriend" action="send_group.php" method="post" onSubmit="return checkfields()">
<table>
<tr>
<td> Your name*:</td>
<td> <input name="name" size="30" maxlength="45"> </td>
</tr>
<tr>
<td>Your email*:</td>
<td><input name="email" size="30" maxlength="45"></td>
</tr>
<tr>
<td colspan="2"><p align="center">Enter your friend's email addresses:</p>
</td>
</tr>
<tr>
<td>Email 1*:</td>
<td><input name="fmail1" class="bordesolid1" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email 2*:</td>
<td><input name="fmail2" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email 3*:</td>
<td><input name="fmail3" size="30" maxlength="50"></td>
</tr>
<tr>
<td colspan="2"><p align="center"><span>This message will contain your name & email address.</span>
<br>
<input onClick="validate();" type="button" value="click once to send">
<input type=hidden name=refurl value="<? print $refurl;?>">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
PHP Code:
<?php
if(count($_POST)) {
foreach(array('fmail1','fmail2','fmail3','email','name') as $key) $_POST[$key] = strip_tags($_POST[$key]);
if(!is_secure($_POST)) {
die("Peace People! Stop Spamming!");
}
$name = $_POST[name];
$email = $_POST[email];
$fmail1 = $_POST[fmail1];
$fmail2 = $_POST[fmail2];
$fmail3 = $_POST[fmail3];
$refurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$to = "arvindsri123#yahoo.com";
$subject = "Recommendation form submission";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message.='<p style="margin-top:10px;">'.$name.' has used your recommendation form using an email address of '.$email.' </p>';
$message.='<p style="margin-top:10px;">The people the recommendation has been submitted to are: </p>';
$message.='<p style="margin-top:10px;">'.$fmail1.' </p>';
$message.='<p style="margin-top:10px;">'.$fmail2.' </p>';
$message.='<p style="margin-top:10px;">'.$fmail3.' </p>';
$message.='<p style="margin-top:10px;">The page recommended:</p>';
$message.='<p style="margin-top:10px;">'.$refurl.'</p>';
$message .= '</body></html>';
$sentmail = mail($to, $subject, $message, $headers);
// $thankyoupage = "thankyou.htm";
//echo $sentmail;
if($sentmail) {
$name = $_POST[name];
$email = $_POST[email];
$fmail1 = $_POST[fmail1];
$fmail2 = $_POST[fmail2];
$fmail3 = $_POST[fmail3];
$refurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$tsubject = "A web page recommendation from $_POST[name]";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message.='<p style="margin-top:10px;">Hi, '.$name.' whose email address is $_POST[email] thought you may be interested in this web page. '.$email.' </p>';
$message.='<p style="margin-top:10px;">'.$refurl.'</p>';
$message .= '</body></html>';
$sentmail = mail($fmail1,$fmail2,$fmail3, $tsubject $message, $headers);
echo '<h4>You have sent emails...</h4>';
//header("Location: $thankyoupage");
exit;
}
function is_secure($ar) {
$reg = "/(Content-Type|Bcc|MIME-Version|Content-Transfer-Encoding)/i";
if(!is_array($ar)) {
return preg_match($reg,$ar);
}
$incoming = array_values_recursive($ar);
foreach($incoming as $k=>$v) if(preg_match($reg,$v)) return false;
return true;
}
function array_values_recursive($array) {
$arrayValues = array();
foreach ($array as $key=>$value) {
if (is_scalar($value) || is_resource($value)) {
$arrayValues[] = $value;
$arrayValues[] = $key;
}
elseif (is_array($value)) {
$arrayValues[] = $key;
$arrayValues = array_merge($arrayValues, array_values_recursive($value));
}
}
return $arrayValues;
}
?>
I am using Bluehost web hosting, and other emails properly working as I said Contact us, Registration confirmation emails.. etc.
Thanks!
If you are running on localhost then it won't send email.. to do so you need to host on server
Try to host on free hosting server.. it will work!
I have the following code:
<table class="table table-striped" id="itemsTable">
<thead>
<tr>
<th></th>
<th>Item Code</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr class="item-row">
<td></td>
<td><input type="text" name="itemCode[]" value="" class="input-medium" id="itemCode"
tabindex="1"/>
</td>
<td><input type="text" name="itemDesc[]" value="" class="input-large" id="itemDesc"
readonly="readonly"/></td>
<td><input type="text" name="itemQty[]" value="" class="input-mini" id="itemQty" tabindex="2"/>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span>
<input
name="itemPrice[]"
class=" input-small"
id="itemPrice"
type="text"></div>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span><input
name="itemLineTotal[]" class=" input-small" id="itemLineTotal" type="text"
readonly="readonly"></div>
</td>
</tr>
</tbody>
</table>
What is the best way to process the inputs via php to send the order via email nicley formated into a table? This is an order form and I need to to simply be sent to an email once complete
Here is my processing code:
<?php
$to = $_REQUEST['xxx'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"itemCode"} = "Code";
$fields{"itemDesc"} = "Description";
$fields{"itemPrice"} = "Price";
$body = "We have received the following information:\n\n";
foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: noreply#example.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
$send = mail($to, $subject, $body);
if($send){
header( "Location:index.php" );
} else {
print "We encountered an error sending your mail, please try again";
}
?>
This code is not working please help
To process a form this way you need to have a form element somewhere in your markup to process.
<form method="POST" action="yourSecondScript.php">
your first markup here
<input type="submit">
<form>
Then to make the email nice with tables you need to set the email headers to html.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_REQUEST['Name'] . ">\r\n";
mail($to, $subject, $body, $headers);
Where is
$to = $_REQUEST['xxx'] ;
coming from? My guess is that you can set it to fixed as you probably don't need a dynamic e-mail to address, so something like:
$to = 'myname#mydomain.com';
But as Michael mentioned in a reaction to your question, we cannot be sure until you tell us which part is not working / what errors you receive and so on..
i'm new in php..i would like to sent contact form to my gmail account..
everything just going fine whrn i click the submit button,but my problem is this form not sending me the email..
this is my html code
<form action="kontact-sent" onSubmit="return validate_form(this)" method="post">
<table width="415" border="0" cellspacing="1" cellpadding="5" class="t1">
<tr>
<td align="left" valign="top" bgcolor="#efefef">First name:<br /><input name="FirstName" type="text" id="FirstName" style="width:300px;" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef">Email address<br /><input type="text" name="EmailAddress" id="EmailAddress" style="width:300px;" />
<input name="Email_Confirmation" class="Email_Confirmation2"/></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef">Message<br /><textarea name="Inquiry" id="Inquiry" style="width:300px; height:100px;"></textarea></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
function validate_EmailAddress(field,alerttxt){
with (field)
{
apos=value.indexOf("#");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(FirstName,"Please enter your First Name.")==false)
{FirstName.focus();return false;}
if (validate_EmailAddress(EmailAddress,"Please enter a valid Email Address.")==false)
{EmailAddress.focus();return false;}
if (validate_Inquiry(Inquiry,"Please enter your Inquiry.")==false)
{Inquiry.focus();return false;}
}
}
this is my .php
<?php
// if the Email_Confirmation field is empty
if(isset($_POST['Email_Confirmation']) && $_POST['Email_Confirmation'] == ''){
// put your email address here scott.langley.ngfa#statefarm.com, slangleys#yahoo.com
$youremail = 'afiqrashid91#gmail.com';
// prepare a "pretty" version of the message
$body .= "Thank You for contacting us! We will get back with you soon.";
$body .= "\r\n";
$body .= "\r\n";
foreach ($_POST as $Field=>$Value) {
$body .= "$Field: $Value\r\n";
$body .= "\r\n";
}
$CCUser = $_POST['EmailAddress'];
// Use the submitters email if they supplied one
// (and it isn't trying to hack your form).
// Otherwise send from your email address.
if( $_POST['EmailAddress'] && !preg_match( "/[\r\n]/", $_POST['EmailAddress']) ) {
$headers = "From: $_POST[EmailAddress]";
} else {
$headers = "From: $youremail";
}
// finally, send the message
mail($youremail, 'Form request', $body, $headers, $CCUser );
}
// otherwise, let the spammer think that they got their message through
?>
Thank You for contacting us! We will get back with you soon.
i hope that anyone can help me..thanks in advance..
$headers = "From: $_POST[EmailAddress]";
Should be:
$headers = "From: $_POST['EmailAddress']";
Also, email messages shouldn't exceed 70 characters per line. You'll want to fix this by adding:
$body = wordwrap($body, 70);
I realise this question has been asked numerous times before but everyone's code is obviously different and I am quite new to php so just looking to see if someone can give me some help.
I have created a basic contact form for a site but for some reason the information is not being sent to my email address although I believe that the form is submitted?
my PHP code is:
<?php
session_start();
//$to_mail = "architects#palavin.com,t.lavin#palavin.com,12yorkcourt#gmail.com";
$to_mail = "danny#enhance.ie";
//$cc="paul#enhance.ie";
$mail_sent = 0;
if(isset($_POST['submit'])){
//echo "the form was submitted";
$error= array();
$name = trim(strip_tags($_POST['name']));
if($name == "")
$error['name'] = 1;
$email = trim(strip_tags($_POST['email']));
if($email == "")
$error['email'] = 1;
$phone = trim(strip_tags($_POST['phone']));
$address = trim(strip_tags($_POST['address']));
$description = trim(strip_tags($_POST['description']));
$str = trim(strip_tags($_POST['secu']));
if ( isset($_SESSION['code_']) && $_SESSION['code_'] == strtoupper($str)){} else {$error['secu'] = 1;}
if(empty($error)){
$headers = 'From: "Euro Insulation" <no-reply#euroinsulations.ie>'."\r\n";
//$headers .= 'CC: "'.$cc.'" <'.$cc.'>'."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "";
$subject = "New contact message";
$message = "New Contact message, received from: <br /> \n ";
$message .= "<b>Name</b> ".$name."<br /> \n";
$message .= "<b>Email</b> ".$email."<br /> \n";
$message .= "<b>Phone</b> ".$phone."<br /> \n";
$message .= "<b>Address</b> ".$address."<br /> \n";
$message .= "<b>Description</b> ".$description."<br /> \n";
if(#mail($to_mail,$subject,$message,$headers ))
{
echo "mail sent";
$mail_sent = 1;
}
else echo "mail not sent";
}
}
?>
my html form looks like this:
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="65%" valign="top"><p class="header"><br>
Contact US <br>
</p>
<?php if($mail_sent==1){
print "Thank you for your message.";
} else { ?>
<form class="email_sub" method="post" >
<table width="77%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td><label for="name" class="formtext" <?php if($error['name']==1) echo "style='color:red;'" ?> >Name:</label></td>
<td><input type="text" name="name" id="text" <?php if($name) echo "value='".$name."'" ?> /></td>
</tr>
<tr>
<td><label for="phone" class="formtext">Number:</label></td>
<td><input type="text" name="phone" id="phone"/><tr>
<br />
<tr>
<td><label for="email" class="textarea" <?php if($error['email']==1) echo "style='color:red;'" ?>>Email:</label></td>
<td><input type="text" name="email" id="email" <?php if($email) echo "value='".$email."'" ?> /></td>
</tr>
<tr>
<td><br /></td>
</tr>
<tr><td><label for="address" class="textarea">Address/Location of project:</label></td>
<td><textarea rows="3" cols="20" name="address" id="address" style="width: 400px;"><?php if($address!="") echo $address ?></textarea></td>
</tr>
<tr>
<td><br /></td>
</tr>
<br />
<tr>
<td><label for="description" class="fixedwidth">Enquiry</label></td>
<td><textarea rows="3" cols="20" name="description" id="description" style="width: 400px;"><?php if($description!="") echo $description; ?></textarea></td>
<tr>
<td><br /></td>
</tr>
<!-- form -->
<tr>
<td><label> </label></td>
<td><input type="submit" value="Submit" name="submit" /></td>
</tr>
</table>
</form>
<?php } ?>
Am i missing something obvious here?? Any help will really be appreciated thanks!
You have used sessions which is not required here, you can also use flag variable instead of arrays in this simple form, use this updated code.
<?php
//$to_mail = "architects#palavin.com,t.lavin#palavin.com,12yorkcourt#gmail.com";
$to_mail = "danny#enhance.ie";
//$cc="paul#enhance.ie";
$mail_sent = 0;
if(isset($_POST['submit'])){
//echo "the form was submitted";
$name = trim(strip_tags($_POST['name']));
if($name == "")
$error = true;
$email = trim(strip_tags($_POST['email']));
if($email == "")
$error = true;
$phone = trim(strip_tags($_POST['phone']));
$address = trim(strip_tags($_POST['address']));
$description = trim(strip_tags($_POST['description']));
if($error != true){
$headers = 'From: "Euro Insulation" <no-reply#euroinsulations.ie>'."\r\n";
//$headers .= 'CC: "'.$cc.'" <'.$cc.'>'."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "";
$subject = "New contact message";
$message = "New Contact message, received from: <br /> \n ";
$message .= "<b>Name</b> ".$name."<br /> \n";
$message .= "<b>Email</b> ".$email."<br /> \n";
$message .= "<b>Phone</b> ".$phone."<br /> \n";
$message .= "<b>Address</b> ".$address."<br /> \n";
$message .= "<b>Description</b> ".$description."<br /> \n";
if(#mail($to_mail,$subject,$message,$headers))
{
echo "mail sent";
$mail_sent = 1;
}
else echo "mail not sent";
} else {
echo 'validation error';
}
}
?>
You have also missed out the else statement for your form validation test so no errors getting displayed when you submit form.
Remove the at sign from mail function and see what errors your get. #mail suppresses errors from being displayed.
Comment out the following line: if ( isset($SESSION['code']) && $SESSION['code'] == strtoupper($str)){} else {$error['secu'] = 1;}
You should be able to reach the mail function.
Here i have a code like getting the data from index.php , if user enter the data it will show like table and as well as it should go to email to some predefined mail. But here i am getting data Dynamically , i tried with $_REQUEST and $_POST both methods to get the data , but in mail function i am trying to change message parameter but by php tags its is not taking and showing some syntax errors.
please go through code here
<?php
$to="xxxxxxx#gmail.com";
$fn="Fisrt Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="xxxxx#xxx.com";
$subject = "Welcome to Website";
include('newsmtp/smtpwork.php');
?>
<?php
$message = 'Dear $firstName,
Your Welcome Message.'.'
<table border=1>
<tr>
<td>First Name:</td>
<td><?php $firstName=$_POST['firstname'];
echo $firstName;?></td>
</tr>
<tr>
<td>Last Name:</td>
<td><?php $lastname=$_POST['lastname'];
echo $lastname;?></td>
</tr>
<tr>
<td>Title:</td>
<td><?php $title=$_POST['title'];
echo $title;?></td>
</tr>
<tr>
<td>Address:</td>
<td><?php $address=$_POST['address'];
echo $address;?></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><?php $phone=$_POST['phone'];
echo $phone;?></td>
</tr>
<tr>
<td>Course Name:</td>
<td><?php $course=$_POST['coursename'];
echo $course;?></td>
</tr>
<tr>
<td>Website:</td>
<td><?php $website=$_POST['website'];
echo $website;?></td>
</tr>
</table>
Thanks
xxxxxxxxxxxx
';
?>
Try this method, assign the posted values in variables, outside the $message variable and print the variable inside your $message variable
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$title = $_POST['title'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$course = $_POST['course'];
$website = $_POST['website'];
$message = 'Dear '.$firstName.',
Your Welcome Message.'.'
<table border=1>
<tr>
<td>First Name:</td>
<td>'.$firstname.' </td>
</tr>
<tr>
<td>Last Name:</td>
<td>'.$lastname.'</td>
</tr>
<tr>
<td>Title:</td>
<td>'.$title.'</td>
</tr>
<tr>
<td>Address:</td>
<td>'.$address.'</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>'.$phone.'</td>
</tr>
<tr>
<td>Course Name:</td>
<td>'.$course.'</td>
</tr>
<tr>
<td>Website:</td>
<td>'.$website.'</td>
</tr>
</table>
Thanks
xxxxxxxxxxxx
';
?>
$to ="xxxxxxx#gmail.com";
$subject = "Welcome to Website";
$headers = 'From: xxxxxx <noreply#xxxxxxx.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\r\n";
$sent = #mail($to,$subject,$message,$headers);
if ($sent) {
return true;
} else {
return false;
}
Also add necessary header to send HTML mail as Vinoth Babu, Naveen suggested
$to = "naveen#gmail.com";
$subject = $name ." is contact ";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\n";
#mail($to,$subject,$message,$headers);
set headers to mime version & type of your message like text/html
To send HTML Content/Tables you have to add the following in the header of that mail,
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
please refer the link below,
Mail Function