Sending an email from an HTML file by calling a PHP component is not working

Hi, I’ve been trying to set up an online ordering platform for my school’s coffee shop where hitting the submit button will automatically send an email including their order information to the cafe’s address. My code seems to go through the PHP file, as when you click submit, a php url appears for a second before it loads the success page, but no email is being sent…

My HTML Button:

[php]



Order Now


×


Name


Email


Small


Regular


Pick-up Time:

7:30
7:35
7:40
7:45
7:50
7:55
8:00
4th Period (ASAP)
5th Period (ASAP)



Place Order



[/php]

and my PHP component:

[php]<?php
if(isset($_POST[‘email’])) {
$email_to = "[email protected]";
$email_subject = “Email subject”;
$name = $_POST[‘name’]; // required
$email_from = $_POST[‘email’]; // required
$size = $_POST[‘size’]; // required
$time = $_POST[‘time’]; // required

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message = "Form details below.\n\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Size: ".clean_string($size)."\n";
$email_message .= "Time: ".clean_string($time)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>

Thank you for your order!
<?php } ?>[/php]

This is where being a member helps far more than allowing Guest questions…

So, the mail function is unreliable at best. It is possible it is actually being received and just landing in the spam folder, it is also possible that it is being rejected by the accepting mail sever as junk and never making it there to begin with.

That said, This is a bad approach to an ordering system to begin with. I understand that you are likely learning, so, is this for an assignment OR for actual use?

Spencer, Don’t know if you are watching or not, but here is an example for you to ponder what I mean…,

For the Employee’s. Bare in mind, this would not be a publicly accessible in the real world.
Orders Pending

For the Customers
Order Page

This could be further advanced and allow cancellations and a slew of other things

Hi!! Thank you for responding, I made an account so I could reply on here. This project is in fact for actual use. I’m trying to put together a website for my school’s cafe in order for staff/students to order drinks ahead of time. The system I was attempting to set up would send an email with the user’s information, choice of size, and pick up time to an account designated for orders. I had an old HTML mailto tag in originally, but I wanted the order button to submit an email automatically without opening the mail tab. This way the staff could have the email account open on their iPad and delete emails as they finished orders. I have a rudimentary version of the site up and running, but it won’t let me post a link since I’m a new user.

https://
spencer-27062.firebaseapp
.com/home

Just delete the returns and the link should work. Everything is working well except for the ordering component. The two pages you linked looked very cool, however, I’m very new to PHP and don’t really know where to start with something other than what I have, but I’m open to learn.

Thanks, Spencer

Sponsor our Newsletter | Privacy Policy | Terms of Service