Log in

View Full Version : form needs "from"



chechu
05-14-2021, 04:59 PM
Hi all, for some reason this form stopped working, and someone said I should add a "from" field. No idea how to, so if anyone can help me out here, great!
This is the code:

<?php

$ip = $_SERVER['REMOTE_ADDR']; // get ip to short variable name for logging purposes

$to = "mail@mywebsite.com";
$subject= "order home delivery 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'];
$beanriceveggie = $_POST['beanriceveggie'];
$aubergine = $_POST['aubergine'];
$beefcurry = $_POST['beefcurry'];
$pistachio = $_POST['pistachio'];
$rafaella = $_POST['rafaella'];
$carrot = $_POST['carrot'];
$almond = $_POST['almond'];
$saffron = $_POST['saffron'];
$jewelled = $_POST['jewelled'];
$book = $_POST['book'];
$remarks = $_POST['remarks'];

$message = "
Name: $name
Phone: $phone
Email: $email

Address: $street, $city

Time of delivery: $date
Delivery: $delivery
Book: $book

Order:
$falafel
$kebab
$chicken
$frittata
$beanrice
$beanriceveggie
$aubergine
$beefcurry
$pistachio
$saffron
$jewelled
$rafaella
$carrot
$almond

Remarks: $remarks

";
$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 "<b>Thanks for your order.</b><br>It will be processed very shortly, so I will get back to you soon.<br>Please stay healthy in the meantime.
<br>&nbsp;<br>&nbsp;<br><blockquote class='bordered layout-2'><b>This was your order:</b>
<br>&nbsp;<br>$name
<br>$street, $city
<br>$phone - $email
<br>&nbsp;<br>$book
<br>&nbsp;<br>$delivery
<br>delivery time: $date
<br>&nbsp;<br>$falafel
<br>$kebab
<br>$chicken
<br>$frittata
<br>$beanrice
<br>$beanriceveggie
<br>$aubergine
<br>$beefcurry
<br>$pistachio
<br>$saffron
<br>$jewelled
<br>$rafaella
<br>$carrot
<br>$almond
<br>&nbsp;<br>Remarks:<br>$remarks</blockquote>
<br>&nbsp;<br><a href='https://mywebsite.com/home-delivery.php' class='btn btn-outline-maincolor'>Missed something - go back</a>
";
else
echo "Your order has not been processed.<br>Please try again, filling in all fields.<br><a href='https://mywebsite.com/home-delivery.php'>&#187; go back</a>";
?>

keyboard
05-26-2021, 08:03 AM
Hey chechu! Can you give any more info on this issue? I did a quick check and there's no syntax errors or anything like that.

Some useful info could be:
What happens when the code runs?
Are there any errors / log outputs?
Does it print the "Thanks" or the "Not Processed"?
Can you check your mail server to see whether it's sending? (e.g., is it not working because the target isn't receiving it, or because the sender isn't sending it?)

chechu
05-26-2021, 08:58 AM
Thanks for your reply, keyboard.

Feel free to fill in the form: https://www.parisaspersiankitchen.com/home-delivery.php
It takes you to the "not sent" message, and indeed I do not receive it.
Regarding your mail server question: no idea how to get that info.

It also seems like it is not working because it does not go with the latest php version.
How to adjust it, please?
Thanks.