I have order confirmation html emails being parsed by a PHP script. The script does a few things successfully but I can’t work out how to get it to search through the email for all product prices, and then to set a flag if the value is greater than £500.
Basically, I’d like the script to send me an email alert if an order is over £500.
Below is what I have so far. $body is the content of the HTML email. I know that part works as the other rules are setup fine. I think my problem is the $pattern rules for preg_match – I don’t think it’s identifying the price values correctly.
Is there a way I can search $body for anything with the format of £xx.xx (where each x is a number) and add 1 to $temp for each value it finds that is greater than £500? I can’t work this out…
if (stristr($body,'Order Confirmation') !== false) {
$string = $body;
$pattern = '/^[0-9]{1,}$/';
preg_match ($pattern, $string, $matches);
$temp = array_filter($matches, function($value) {
return $value >= 500;
});
if ($temp >= 1)
{
$headers = "Content-type: text/html \r\n";
$headers .= "From: Robot<robot@robot.com>";
mail('joe@blogs.com','Internet Order Value Over £500', $body, $headers);
}
}
I think this will do what you want. the code should work if you copy-and-paste into a file with a php extension. You’ll have to edit it slightly for your script.