-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhd-mail.php
More file actions
113 lines (89 loc) · 3.39 KB
/
hd-mail.php
File metadata and controls
113 lines (89 loc) · 3.39 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
$http_origin = $_SERVER['HTTP_ORIGIN'];
if ($http_origin == "http://preview.happy-dev.fr" || $http_origin == "http://www.happy-dev.fr" || $http_origin == "http://happy-dev.fr" || $http_origin == "https://happy-dev.fr" || $http_origin == "https://www.happy-dev.fr")
{
header("Access-Control-Allow-Origin: $http_origin");
}
header("Access-Control-Allow-Methods: POST");
/**
* Plugin Name: HD MAIL
* Description: This is a test for sending via ajax and wordpress wp-mail for the Happy-Dev website.
* Author: Jonathan BRALEY
* License: GPL2
*/
add_action("wp_ajax_send_HD_mail","HD_wp_ajax_send_mail");
add_action("wp_ajax_nopriv_send_HD_mail","HD_wp_ajax_send_mail");
function HD_wp_ajax_send_mail(){
if(isset($_POST["name"]) && isset($_POST["howru"]) && isset($_POST["request"]) && isset($_POST["contact"]) && isset($_POST["mails"]) && isset($_POST["action"])){
$message= "Bonjour Happy Dev,
".$_POST["name"]." cherche à vous contacter.
Lors de sa demande ça allait : ".$_POST["howru"]."
Sujet de la demande:
".$_POST["request"]."
Vous pourrez le joindre de cette manière : ".$_POST["contact"]."
Bonne journée!";
//$res = wp_mail($_POST["mails"],$_POST["name"]." cherche à vous contacter",$message);
/**
* Send a ping to the favorite chat app with the message
*/
if (defined('CHAT_APP') && CHAT_APP == 'ROCKET_CHAT' && function_exists('rocketChat') ) {
rocketChat('@all ' . $message);
} else if (function_exists('slack')) {
slack('<!channel> ' . $message);
}
echo res;
} else {
echo -1;
}
}
/**
* Quick Slack webhook integration
* @source https://gist.github.com/alexstone/9319715
*/
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
function slack($message, $room = "smile", $icon = ":simple_smile:") {
if (!function_exists('curl_init')) {
error_log('php-curl missing');
return;
}
if (!defined('SLACK_WEBHOOK')) {
error_log('SLACK_WEBHOOK must be defined in wp-config.php');
return;
}
$room = ($room) ? $room : "email";
$data = "payload=" . json_encode(array(
"username" => "Website",
"channel" => "#{$room}",
"text" => $message,
"icon_emoji" => $icon
));
// You can get your webhook endpoint from your Slack settings
$ch = curl_init(SLACK_WEBHOOK);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function rocketChat($message) {
if (!function_exists('curl_init')) {
error_log('php-curl missing');
return;
}
if (!defined('ROCKETCHAT_WEBHOOK')) {
error_log('ROCKETCHAT_WEBHOOK must be defined in wp-config.php');
return;
}
$data = "payload=" . json_encode(array("text" => $message ));
// You can get your webhook endpoint from your Slack settings
$ch = curl_init(ROCKETCHAT_WEBHOOK);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}