<?php header('Access-Control-Allow-Origin: *'); require_once 'src/autoload.php'; $phone_number = $_POST['phone_number']; $address = $_POST['address']; $parameter = $_POST['parameter']; $operator = $_POST['operator']; $value = $_POST['value']; $email = $_POST['email']; $notification = $_POST['notification']; $email_from = "*****@*****.**"; if ($notification == 1) { $message = new \Esendex\Model\DispatchMessage("WebApp", $phone_number, "Alarma en el sensor situado en: " . $address . " (" . $parameter . " " . $operator . " " . $value . ").", \Esendex\Model\Message::SmsType); $authentication = new \Esendex\Authentication\LoginAuthentication("EX0092384", "*****@*****.**", "UPhzHJpzKVMh"); $service = new \Esendex\DispatchService($authentication); $result = $service->send($message); echo "sms_success"; } else { $email_subject = "Alerta de " . $parameter . ""; $email_message = "Alarma en el sensor situado en: " . $address . " (" . $parameter . " " . $operator . " " . $value . ")."; $headers = 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($email, $email_subject, $email_message, $headers)) { echo "email_success"; } else { echo "email_failure"; } }
/** * Launch the campaign * * @return void **/ public function launch() { $status = "send"; $query = Core::query('campaign-new-status'); $query->bindValue(':status', $status); $query->bindValue(':campaign', $this->_campaign['id'], PDO::PARAM_INT); $query->execute(); $query = Core::query('campaign-contacts'); $query->bindValue(':campaign', $this->_campaign['id'], PDO::PARAM_INT); $query->execute(); $contacts = $query->fetchAll(PDO::FETCH_NUM); switch ($this->_campaign['type']) { case 'email': $query = Core::query('contact-emails'); foreach ($contacts as $contact) { $query->bindValue(':contact', $contact[0], PDO::PARAM_INT); $query->execute(); $_emails = $query->fetchAll(PDO::FETCH_NUM); foreach ($_emails as $_email) { $this->trackingNew($_email[0]); } } break; case 'sms': // On assure le démarrage du service $service = new \Esendex\DispatchService(Configuration::read('sms')); $query = Core::query('mobiles-by-contact'); foreach ($contacts as $contact) { $query->bindParam(':contact', $contact[0], PDO::PARAM_INT); $query->execute(); $_sms = $query->fetchAll(PDO::FETCH_NUM); foreach ($_sms as $_element) { $sms = new \Esendex\Model\DispatchMessage(Configuration::read('sms.sender'), $_element[0], $this->_campaign['message'], \Esendex\Model\Message::SmsType); $result = $service->send($sms); $this->tracking($result, $_element[0], $contact[0]); } } } }