chechu
04-08-2020, 02:28 PM
Hey all,
I have this php mail form code which works fine.
I would just like to add a code so that the sender of the mail through the form, receives a confirmation mail.
What code needs to be added and where, please?
Thanks.
<?php
$ip = $_SERVER['REMOTE_ADDR']; // get ip to short variable name for logging purposes
$to = "info@mysite.com";
$subject= "order via website";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$street = $_POST['street'];
$city = $_POST['city'];
$date = $_POST['date'];
$delivery = $_POST['delivery'];
$falafel = $_POST['falafel'];
$kebab = $_POST['kebab'];
$chicken = $_POST['chicken'];
$frittata = $_POST['frittata'];
$beanrice = $_POST['beanrice'];
$aubergine = $_POST['aubergine'];
$beefcurry = $_POST['beefcurry'];
$pistachio = $_POST['pistachio'];
$saffron = $_POST['saffron'];
$jewelled = $_POST['jewelled'];
$book = $_POST['book'];
$message = "
Name: $name
Phone: $phone
Email: $email
Address: $street $city
Time of delivery: $date
Delivery: $delivery
Order:
$falafel
$kebab
$chicken
$frittata
$beanrice
$aubergine
$beefcurry
$pistachio
$saffron
$jewelled
$book
";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $email\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
foreach($_FILES as $userfile)
{
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name))
{
if(is_uploaded_file($tmp_name))
{
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
$message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
echo "Thanks for your order.<br>It will be processed very shortly, so I will get back to you soon.<br>Please stay healthy in the meantime.";
else
echo "Your order has not been processed.<br>Please try again, filling in all fields.";
?>
I have this php mail form code which works fine.
I would just like to add a code so that the sender of the mail through the form, receives a confirmation mail.
What code needs to be added and where, please?
Thanks.
<?php
$ip = $_SERVER['REMOTE_ADDR']; // get ip to short variable name for logging purposes
$to = "info@mysite.com";
$subject= "order via website";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$street = $_POST['street'];
$city = $_POST['city'];
$date = $_POST['date'];
$delivery = $_POST['delivery'];
$falafel = $_POST['falafel'];
$kebab = $_POST['kebab'];
$chicken = $_POST['chicken'];
$frittata = $_POST['frittata'];
$beanrice = $_POST['beanrice'];
$aubergine = $_POST['aubergine'];
$beefcurry = $_POST['beefcurry'];
$pistachio = $_POST['pistachio'];
$saffron = $_POST['saffron'];
$jewelled = $_POST['jewelled'];
$book = $_POST['book'];
$message = "
Name: $name
Phone: $phone
Email: $email
Address: $street $city
Time of delivery: $date
Delivery: $delivery
Order:
$falafel
$kebab
$chicken
$frittata
$beanrice
$aubergine
$beefcurry
$pistachio
$saffron
$jewelled
$book
";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $email\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
foreach($_FILES as $userfile)
{
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name))
{
if(is_uploaded_file($tmp_name))
{
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
$message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
echo "Thanks for your order.<br>It will be processed very shortly, so I will get back to you soon.<br>Please stay healthy in the meantime.";
else
echo "Your order has not been processed.<br>Please try again, filling in all fields.";
?>