0

EDIT: This is different from the possible duplicate, as they never got the email. Mine sends randomly.

The code below has been working fine for almost a year. For about the past week, however, it only sends when it wants to. My guys use it at multiple locations on multiple devices, and the same thing is happeneing.

There's an html form that submits to this php code, which then emails me and displays an html confirmation page. They're getting the confirmation page, but I'm not getting the email. Later in the day, if I hit back, then submit again, I do get the email.

I can't figure it out. Any suggestions as to what's happening? I'm considering making a SQL database that it submits to first, so that I can look up what they entered incase I don't get the email.

Thanks!

<?php
if(isset($_POST['submit'])) {
$to = "email_removed@gmail.com";
$subject = "Daily Inventory Submission";

// data the visitor provided
$location_field = filter_var($_POST['location'], FILTER_SANITIZE_STRING);
$yourname_field = filter_var($_POST['yourname'], FILTER_SANITIZE_STRING);
$biscuitsfull_field = filter_var($_POST['biscuits_full'], FILTER_SANITIZE_STRING);
$biscuitspartial_field = filter_var($_POST['biscuits_partial'], FILTER_SANITIZE_STRING);
$biscuitsemergency_field = filter_var($_POST['biscuits_emergency'], FILTER_SANITIZE_STRING);
$gravyfull_field = filter_var($_POST['gravy_full'], FILTER_SANITIZE_STRING);
$gravypartial_field = filter_var($_POST['gravy_partial'], FILTER_SANITIZE_STRING);
$eggsfull_field = filter_var($_POST['eggs_fullflats'], FILTER_SANITIZE_STRING);
$eggspartial_field = filter_var($_POST['eggs_partial'], FILTER_SANITIZE_STRING);
$cheese_field = filter_var($_POST['cheese'], FILTER_SANITIZE_STRING);
$sausagefull_field = filter_var($_POST['sausage_full'], FILTER_SANITIZE_STRING);
$sausagepartial_field = filter_var($_POST['sausage_partial'], FILTER_SANITIZE_STRING);
$jalapenos_field = filter_var($_POST['jalapenos'], FILTER_SANITIZE_STRING);
$sprayoil_field = filter_var($_POST['spray_oil_cans'], FILTER_SANITIZE_STRING);
$pouroil_field = filter_var($_POST['pour_oil'], FILTER_SANITIZE_STRING);
$tofu_field = filter_var($_POST['tofu'], FILTER_SANITIZE_STRING);
$almondmilk_field = filter_var($_POST['almond_milk'], FILTER_SANITIZE_STRING);
$veganbutter_field = filter_var($_POST['vegan_butter'], FILTER_SANITIZE_STRING);
$realbutter_field = filter_var($_POST['real_butter'], FILTER_SANITIZE_STRING);
$bacon_field = filter_var($_POST['bacon'], FILTER_SANITIZE_STRING);
$togo_field = filter_var($_POST['to_go'], FILTER_SANITIZE_STRING);
$hereboats_field = filter_var($_POST['here_boats'], FILTER_SANITIZE_STRING);
$flour_field = filter_var($_POST['flour'], FILTER_SANITIZE_STRING);
$potatoes_field = filter_var($_POST['potatoes'], FILTER_SANITIZE_STRING);
$waters_field = filter_var($_POST['waters'], FILTER_SANITIZE_STRING);
$oj_field = filter_var($_POST['orange_juice'], FILTER_SANITIZE_STRING);
$topo_field = filter_var($_POST['topo'], FILTER_SANITIZE_STRING);
$cokes_field = filter_var($_POST['cokes'], FILTER_SANITIZE_STRING);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);




//constructing the message
$body = " 
Location: $location_field\n 
Employee: $yourname_field\n\n 

Biscuits_FULL:      $biscuitsfull_field\n
Biscuits_Partial:   $biscuitspartial_field\n
Biscuits_Emergency: $biscuitsemergency_field\n\n

Gravy_Full:    $gravyfull_field\n
Gravy_Partial: $gravypartial_field\n\n

Eggs_Full:    $eggsfull_field\n
Eggs_Partial: $eggspartial_field\n\n

Cheese:  $cheese_field\n\n

Sausage_Full:    $sausagefull_field\n
Sausage_Partial: $sausagepartial_field\n\n

Jalapenos:  $jalapenos_field\n\n

Spray Oil Cans:  $sprayoil_field\n
Pour Oil :       $pouroil_field\n\n

Tofu:         $tofu_field\n
Almond Milk:  $almondmilk_field\n
Vegan Butter: $veganbutter_field\n\n

Real Butter: $realbutter_field\n\n

Bacon: $bacon_field\n\n

To Go Boxes:  $togo_field\n
Here Boats:   $hereboats_field\n\n

Flour:    $flour_field\n
Potatoes: $potatoes_field\n\n

Waters:        $waters_field\n
Daiya:         $oj_field\n
Topos:         $topo_field\n
Cokes:         $cokes_field\n\n






Message:\n\n $comment";

mail($to, $subject, $body);

// redirect to confirmation
header('Location: confirmation.htm');
} else {
echo "Error, not sent";}
?>
  • Are you sure if the mail server is not queuing sent mails for long time? – Ali Sheikhpour May 30 '16 at 20:48
  • I never receive them. Both stores tried it at 2 today and I didn't receive it. I've been testing it and I get those. If it were queued, wouldn't I get the ones they submitted in addition to mine? – assemblyhelpneededplease May 30 '16 at 20:53
  • Did you check your badmail folder? –  May 30 '16 at 21:03
  • Do you have root access to the server? Can you check the contents of /var/log/mail.log or /var/log/mail.err? The mails you send don't just disappear (most of the times). You may find some clues about what happened on those files. – martintama May 31 '16 at 02:07

1 Answers1

1

I would suggest using a class specifically designed for this purpose instead of using the raw mail function, look up https://github.com/PHPMailer/PHPMailer.

user5470921
  • 576
  • 1
  • 6
  • 16
  • Linking to that other answer does nothing to improve your answer. It also doesn't make your answer useful as you have not shown that any of the items listed in that answer actually is the OP's problem. – John Conde May 30 '16 at 21:05
  • @JohnConde This is different from the possible duplicate, as they never got the email. Mine sends randomly. – assemblyhelpneededplease May 30 '16 at 21:07
  • @assemblyhelpneededplease whether it's none making it through or just some the troubleshooting steps are the same. – John Conde May 30 '16 at 21:09