1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = sanitize_text_field($_POST['name']);
$email = sanitize_email($_POST['email']);
$message = sanitize_textarea_field($_POST['message']);
// Envoi du mail via wp_mail
$to = 'newsletter@example.com';
$subject = 'New Contact Form Submission';
$body = "Name: $name\nEmail: $email\nMessage: $message";
$email_sent = wp_mail($to, $subject, $body);
// Creer un contact dans Mailjet
$apiKey = 'mon_mailjet_api_key';
$apiSecret = 'mon_mailjet_api_secret';
$url = 'https://api.mailjet.com/v3/REST/contact';
$data = [
'Data' => [
'Email' => $email,
'Name' => $name,
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$apiKey:$apiSecret");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?> |
Partager