notification sms et mail automatique en php

Solutions on MaxInterview for notification sms et mail automatique en php by the best coders in the world

showing results for - "notification sms et mail automatique en php"
Sophie
11 Jan 2017
1const ERROR_API = "Error during API call\n";
2const ERROR_FILE = "The specified file does not exist\n";
3const URL = "https://api.smsmode.com/http/1.6/";
4const PATH_SEND_SMS = "sendSMS.do";
5const PATH_SEND_SMS_BATCH = "sendSMSBatch.do";
6 
7/**
8*    Function parameters:
9*
10*    - accessToken (required)
11*    - message (required)
12*    - destinataires (required): Receivers separated by a comma
13*    - emetteur (optional): Allows to deal with the sms sender
14*    - optionStop (optional): Deal with the STOP sms when marketing send (cf. API HTTP documentation)
15*    - batchFilePath (required for batch mode): The path of CSV file for sms in Batch Mode
16*/
17 
18class ExempleClientHttpApi 
19{
20 // send SMS with GET method
21 public function sendSmsGet($accessToken, $message, $destinataires, $emetteur, $optionStop) 
22 {
23     $message = iconv("UTF-8", "ISO-8859-15", $message);
24     $fields_string = '?accessToken='.$accessToken.'&message='.urlencode($message).'&numero='.$destinataires.'&emetteur='.$emetteur.'&stop='.$optionStop;
25  
26     $ch = curl_init();
27     curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
28     curl_setopt($ch,CURLOPT_URL, URL.PATH_SEND_SMS.$fields_string);
29     $result = curl_exec($ch);
30     curl_close($ch);
31     if (!$result) {
32         return ERROR_API;
33     }
34     return $result;
35 }
36 
37 // send SMS with POST method
38 public function sendSmsPost($accessToken, $message, $destinataires, $emetteur, $optionStop) 
39 {
40     $message = iconv("UTF-8", "ISO-8859-15", $message);
41     $fields_string = 'accessToken='.$accessToken.'&message='.urlencode($message).'&numero='.$destinataires.'&emetteur='.$emetteur.'&stop='.$optionStop;
42  
43     $ch = curl_init();
44     curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
45     curl_setopt($ch,CURLOPT_URL, URL.PATH_SEND_SMS);
46     curl_setopt($ch,CURLOPT_POST, 1);
47     curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
48     $result = curl_exec($ch);
49     curl_close($ch);
50     if (!$result) {
51         return ERROR_API;
52     }
53     return $result;
54 }
55 
56 // send SMS with POST method (Batch)
57 public function sendSmsBatch($accessToken, $batchFilePath, $optionStop) 
58 {
59     if (!file_exists($batchFilePath)) {
60         return ERROR_FILE;
61     }
62 
63     $fields_string = '?accessToken='.$accessToken.'&stop='.$optionStop;
64     $cfile = new CurlFile($batchFilePath, 'text/csv');
65     $data = array('data-binary' => $cfile);
66 
67     $ch = curl_init();
68     curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
69     curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'content-type: multipart/form-data'));
70     curl_setopt($ch,CURLOPT_URL, URL.PATH_SEND_SMS_BATCH.$fields_string);
71     curl_setopt($ch,CURLOPT_POST, 1);
72     curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
73     $result = curl_exec($ch);
74     curl_close($ch);
75     if (!$result) {
76         return ERROR_API;
77     }
78     return $result;
79 }
80}
81