| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Created by PhpStorm. | 
					
						
							|  |  |  |  * User: freuddebian | 
					
						
							|  |  |  |  * Date: 08/10/18 | 
					
						
							|  |  |  |  * Time: 12:26 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | error_reporting(E_ALL); | 
					
						
							|  |  |  | ini_set('display_errors', 1); | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  | //include "../../vendor/autoload.php";
 | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  | use Twilio\Rest\Client; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  | // Import PHPMailer classes into the global namespace
 | 
					
						
							|  |  |  | // These must be at the top of your script, not inside a function
 | 
					
						
							|  |  |  | use PHPMailer\PHPMailer\PHPMailer; | 
					
						
							|  |  |  | use PHPMailer\PHPMailer\SMTP; | 
					
						
							|  |  |  | use PHPMailer\PHPMailer\Exception; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Load Composer's autoloader
 | 
					
						
							|  |  |  | require '../vendor/autoload.php'; | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Messenger | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     private $contact; | 
					
						
							|  |  |  |     private $message; | 
					
						
							|  |  |  |     private $mail; | 
					
						
							|  |  |  |     private $subject; | 
					
						
							|  |  |  |     private $client; | 
					
						
							|  |  |  |     private $header; | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |     private $receiverMail; | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     const AccountSid = "ACacdb9c9601741af001ebbc7eca4969cd"; | 
					
						
							|  |  |  |     const AuthToken = "e0e2f1176c09b3980c9ecf967187191b"; | 
					
						
							|  |  |  |     const sender_name = "iLink World"; | 
					
						
							|  |  |  |     const sender_number = "+447400348273"; | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Messenger constructor. | 
					
						
							|  |  |  |      * @param $contact | 
					
						
							|  |  |  |      * @param $message | 
					
						
							|  |  |  |      * @param $mail | 
					
						
							|  |  |  |      * @param $subject | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct($contact=null, $message=null, $mail=null, $subject=null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->contact = $contact; | 
					
						
							|  |  |  |         $this->message = $message; | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |         // Instantiation and passing `true` enables exceptions
 | 
					
						
							|  |  |  |         $this->mail = new PHPMailer(true); | 
					
						
							|  |  |  | //        $this->mail = $mail;
 | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |         $this->subject = $subject; | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         //Server settings
 | 
					
						
							|  |  |  | //        $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
 | 
					
						
							|  |  |  |         $this->mail->isSMTP();                                            // Send using SMTP
 | 
					
						
							|  |  |  |         $this->mail->Host       = 'mail.ilink-app.com';                    // Set the SMTP server to send through
 | 
					
						
							|  |  |  |         $this->mail->SMTPAuth   = true;                                   // Enable SMTP authentication
 | 
					
						
							|  |  |  |         $this->mail->Username   = 'noreply@ilink-app.com';                     // SMTP username
 | 
					
						
							|  |  |  |         $this->mail->Password   = 'ilink2017GA';                               // SMTP password
 | 
					
						
							|  |  |  |         $this->mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
 | 
					
						
							|  |  |  |         $this->mail->Port       = 587; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $this->client = new Client(Messenger::AccountSid,Messenger::AuthToken); | 
					
						
							|  |  |  |         }catch (Exception $e){ | 
					
						
							|  |  |  |             echo $e->getMessage(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     public function sendSms() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |           /*  $sms = $this->client->account->messages->create( | 
					
						
							|  |  |  | // the number we are sending to - Any phone number
 | 
					
						
							|  |  |  |                 $this->getContact(), | 
					
						
							|  |  |  |                 array( | 
					
						
							|  |  |  |                     // Step 6: Change the 'From' number below to be a valid Twilio number
 | 
					
						
							|  |  |  |                     // that you've purchased
 | 
					
						
							|  |  |  |                     'from' => Messenger::sender_number, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     'body' => $this->getMessage() | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             );*/ | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         }catch(Exception $e){ | 
					
						
							|  |  |  |         //    echo json_encode(["message"=>$e->getMessage(),"line"=>$e->getLine(),"trace"=>$e->getTrace()]);
 | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     public function sendMail(){ | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |         //Recipients
 | 
					
						
							|  |  |  |         $this->mail->setFrom('noreply@ilink-app.com', 'Ilink World'); | 
					
						
							|  |  |  |         $this->mail->addAddress($this->getReceiverMail());     // Add a recipient
 | 
					
						
							|  |  |  |         // Content
 | 
					
						
							|  |  |  | //        $this->mail->isHTML(true);                                  // Set email format to HTML
 | 
					
						
							|  |  |  |         $this->mail->Subject = $this->getSubject(); | 
					
						
							|  |  |  |         $this->mail->Body    = $this->getMessage(); | 
					
						
							|  |  |  | //        $this->mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->mail->send(); | 
					
						
							|  |  |  | //       return mail($this->getMail(),$this->getSubject(),$this->getMessage(),$this->getHeader());
 | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return mixed | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getHeader() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->header; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param mixed $header | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setHeader($header) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->header = $header; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return null | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getContact() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->contact; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param null $contact | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setContact($contact) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->contact = $contact; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return null | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getMessage() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->message; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param null $message | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setMessage($message) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->message = $message; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return null | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |     public function getReceiverMail() | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |         return $this->receiverMail; | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param null $mail | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |     public function setReceiverMail($mail) | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  |         $this->receiverMail = $mail; | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return null | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getSubject() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->subject; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param null $subject | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setSubject($subject) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->subject = $subject; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 14:51:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 10:09:26 +00:00
										 |  |  |     public function checkPhoneExist($phone) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $phone_number = $this->client->lookups->v1->phoneNumbers($phone) | 
					
						
							|  |  |  |                 ->fetch(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return isset($phone_number); | 
					
						
							|  |  |  |         } catch(Exception $ex){ | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |