$title,
‘post_content’ => $content,
‘post_status’ => ‘pending’, // Post will be pending for review
‘post_type’ => ‘post’,
‘post_category’ => array($mp_category_id) // Assign post to the “Open Letter” category
);
// Insert the post and get the post ID
$post_id = wp_insert_post($post_data);
// Check if the post was successfully created
if ($post_id) {
// Send email to MP
$subject = ‘New Open Letter Submitted to You’;
$message = “An open letter has been submitted to you.\n\n”;
$message .= “Title: $title\n\n”;
$message .= “Content:\n$content\n\n”;
$message .= “From: $user_email\n\n”;
$message .= “View it here (after approval): ” . get_permalink($post_id);
// Send the email to the MP
wp_mail($mp_email, $subject, $message);
// Show confirmation message
echo ‘
✅ Your letter has been submitted and is awaiting moderation.
‘;
} else {
// Show error message if post creation failed
echo ‘
❌ There was an error submitting your letter. Please try again.
‘;
}
}
// Display the form
?>