I have created a webhook url. the following is the code which checks an order status change to “shipped” and sends some emails depending on the custom field value:
$json = file_get_contents(‘php://input’);
$body = json_decode($json, true);
$api_key = ‘SECRET_API_KEY’;
if (is_null($body) or !isset($body[‘eventName’])) {
header('HTTP/1.1 400 Bad Request');
return;
}
switch ($body[‘eventName’]) {
case 'order.status.changed':
    // Check if the new order status is "shipped"
    if ($body['newStatus'] === 'shipped') {
        // Loop through the order items and check for custom fields
        foreach ($body['content']['items'] as $item) {
            if (isset($item['customFields'])) {
                foreach ($item['customFields'] as $field) {
                  $to = 'mytest@email.com'; //$body['content']['email']
                  $orderInvoiceNumber = $body['orderToken'];
                  $subject = 'email subject';
                  $message = 'email content';
                  $headers = "MIME-Version: 1.0\r\n";
                  $headers .= "Content-type: text/html; charset=UTF-8\r\n";
                  $headers .= "From: myemail@testing.com\r\n";
                  $headers .= "Authorization: Bearer " . $api_key . "\r\n";
                    if ($field['name'] === 'Assignment Type' && $field['value'] === 'Do It Yourself') {
                      mail($to, $subject, $message, $headers);
                      break 2;
                    }
                    if ($field['name'] === 'Assignment Type' && $field['value'] === 'Fast Track') {
                      mail($to, $subject, $message, $headers);
                      break 2;
                    }
                }
            }
        }
    }
    break;
}
using postman, i get status 200 and the emails are recieved. when i try this in snipcart, the webhooks dashboard gives me status code 500: " ```
An error occurred while sending the request.
[ConnectFailure] Unable to connect to the remote server
[10013] An attempt was made to access a socket in a way forbidden by its access permissions