[ [ 'to' => [ [ 'email' => ADAIRE_FEEDBACK_TO ] ], 'subject' => 'GutenBlocks Deactivation Feedback', ], ], 'from' => [ 'email' => ADAIRE_FEEDBACK_FROM, 'name' => 'GutenBlocks' ], 'content' => [ [ 'type' => 'text/plain', 'value' => $body ] ], ]; if ( filter_var( $email, FILTER_VALIDATE_EMAIL ) ) { $payload['reply_to'] = [ 'email' => $email ]; } $ch = curl_init( 'https://api.sendgrid.com/v3/mail/send' ); curl_setopt_array( $ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . ADAIRE_SENDGRID_API_KEY, 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode( $payload ), ] ); $response = curl_exec( $ch ); $status = (int) curl_getinfo( $ch, CURLINFO_HTTP_CODE ); $curl_err = curl_error( $ch ); curl_close( $ch ); if ( $status >= 200 && $status < 300 ) { http_response_code( 200 ); echo json_encode( [ 'ok' => true ] ); } else { http_response_code( 500 ); echo json_encode( [ 'ok' => false, 'status' => $status, 'error' => $curl_err ?: substr( $response, 0, 200 ) ] ); } // ------------------------------------------------------------------------- function sanitize( $value ) { return htmlspecialchars( strip_tags( trim( (string) $value ) ), ENT_QUOTES, 'UTF-8' ); }