Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Created September 2, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickposner/81a148b28dde8cbd611197cf3919b9ac to your computer and use it in GitHub Desktop.
Save patrickposner/81a148b28dde8cbd611197cf3919b9ac to your computer and use it in GitHub Desktop.
Send Mail from Webhook with plain PHP
<?php
// Check if the webhook should be fired.
if ( ! isset( $_GET['mailme'] ) ) {
return;
}
// Check if there is POST request.
if ( empty( $_POST ) ) {
return;
}
// iterate over $_POST request and build message.
$message = '';
foreach ( $_POST as $key => $value ) {
$message .= '<p><b>' . htmlspecialchars( $key ) . '</b>: ' . htmlspecialchars( $value ) . '<p>' . PHP_EOL;
}
// Send mail with PHP.
mail("contact@mywebsite.com","A new submission", $message );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment