Advertisement
Guest User

Untitled

a guest
May 31st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Request returned status 400
  2.  
  3. private static $outlookApiUrl = "https://outlook.office.com/api/v2.0";
  4.  
  5. public static function sendMail ($access_token,$user_email,$subject,$Content,$email){
  6.  
  7. $arr= array(
  8. "Message" =>array(
  9. 'Subject' => $subject,
  10. "Body"=>array(
  11. "Content-Type"=>"HTML",
  12. "Content"=>$Content,
  13. ),
  14. "ToRecipients"=>array(
  15. array(
  16. "EmailAddress"=>array(
  17. "Address"=>$email,
  18. )
  19. ),
  20. ),
  21. ));
  22.  
  23. $json=json_encode($arr, true);
  24.  
  25. $getMessagesUrl = self::$outlookApiUrl."/me/sendmail";
  26.  
  27.  
  28. return self::makeApiCall($access_token, $user_email, "POST",$getMessageUrl,$json);
  29.  
  30. }
  31.  
  32. public static function makeApiCall($access_token, $user_email, $method, $url, $payload = NULL) {
  33. // Generate the list of headers to always send.
  34. $headers = array(
  35. "User-Agent: php-tutorial/1.0",
  36. "Authorization: Bearer ".$access_token,
  37. "Accept: application/json",
  38. "client-request-id: ".self::makeGuid(),
  39. "return-client-request-id: true",
  40. "X-AnchorMailbox: ".$user_email
  41. );
  42.  
  43. $curl = curl_init($url);
  44.  
  45. switch(strtoupper($method)) {
  46. case "POST":
  47. error_log("Doing POST");
  48. $headers[] = "Content-Type: application/json";
  49. curl_setopt($curl, CURLOPT_POST, true);
  50. curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
  51. break;
  52. default:
  53. error_log("INVALID METHOD: ".$method);
  54. exit;
  55. }
  56.  
  57. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  58. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  59. $response = curl_exec($curl);
  60. error_log("curl_exec done.");
  61.  
  62. $curl_errno = curl_errno($curl);
  63. $curl_err = curl_error($curl);
  64. if ($curl_errno) {
  65. //PRINT ERROR
  66. }
  67. else {
  68. error_log("Response: ".$response);
  69. curl_close($curl);
  70. return json_decode($response, true);
  71. }
  72. }
  73.  
  74. $send=OutlookService::sendMail($_SESSION["access_token"], $_SESSION["user_email"],"testing","<html><body>testing email.</body></html>","example@gmail.com");
  75.  
  76. echo var_dump($send);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement