Guest User

Untitled

a guest
Jan 3rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <?php
  2. include('vendor/autoload.php');
  3.  
  4. use prodigyview\network\Socket;
  5. use prodigyview\system\Security;
  6.  
  7. use PHPMailer\PHPMailer\PHPMailer;
  8. use PHPMailer\PHPMailer\Exception;
  9.  
  10.  
  11. $server = new Socket('127.0.0.1', 8002, array(
  12. 'bind' => true,
  13. 'listen' => true
  14. ));
  15.  
  16. $server->startServer('', function($message) {
  17.  
  18. echo "Processing...\n";
  19.  
  20. //Decrypt our encrypted message
  21. Security::init();
  22. $message = Security::decrypt($message);
  23.  
  24. //Turn the data into an array
  25. $data = json_decode($message, true);
  26.  
  27. $response = 'Not Sent';
  28.  
  29. //Verify that the correct token is being used
  30. if(isset($data['token']) && $data['token']=='ABC123-NotRealToken') {
  31.  
  32. try{
  33. $mail = new PHPMailer(true);
  34.  
  35. $mail->Host = 'smtp1.example.com;smtp2.example.com';
  36. $mail->SMTPAuth = true;
  37. $mail->Username = 'user@example.com';
  38. $mail->Password = 'secret';
  39. $mail->SMTPSecure = 'tls';
  40. $mail->Port = 587;
  41.  
  42. $mail->setFrom('from@example.com', 'Mailer');
  43. $mail->addAddress($data['email'], $data['to']);
  44.  
  45. $mail->isHTML(true);
  46. $mail->Subject = $data['subject'];
  47. $mail->Body = $data['message_html'];
  48. $mail->AltBody = $data['message_text'];
  49.  
  50. $mail->send();
  51.  
  52. $response = 'Message Sent';
  53. } catch (Exception $e) {
  54. echo 'Log the error somewhere';
  55. }
  56. }
  57.  
  58. //Return an encrypted message
  59. return Security::encrypt($response);
  60.  
  61. }, 'closure');
Add Comment
Please, Sign In to add comment