PHP-EWS No Data Received Message - exchangewebservices

I just downloaded PHP-EWS, installed following the README instructions, and spun up a script to test out its functionalities. When I try running the script in my browser, I get the following message:
I get the same message when I supply a login I know is invalid. It seems I am connecting to my Exchange server, but it's not recognizing the credentials I provide.
Here is the script I am using
<?php
function __autoload($className)
{
$className = str_replace('_','/', $className);
$sFileName = $className . '.php';
if (file_exists($sFileName) && !class_exists($className))
{
require_once $sFileName;
}
// If the above if fails, you're program will terminate, there is no way to catch this.
}
include("ExchangeWebServices.php");
$host = "https://myexchange/EWS/Services.wsdl";
$username = "myusername#mydomain.com";
$password = "mypassword";
$ews = new ExchangeWebServices($host, $username, $password);
$request = new EWSType_FindItemType();
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;
// sort order
$request->SortOrder = new EWSType_NonEmptyArrayOfFieldOrdersType();
$request->SortOrder->FieldOrder = array();
$order = new EWSType_FieldOrderType();
// sorts mails so that oldest appear first
// more field uri definitions can be found from types.xsd (look for UnindexedFieldURIType)
$order->FieldURI->FieldURI = 'item:DateTimeReceived';
$order->Order = 'Ascending';
$request->SortOrder->FieldOrder[] = $order;
$response = $ews->FindItem($request);
echo '<pre>'.print_r($response, true).'</pre>';
?>

Try testing your access by:
Hitting the server url directly: https://YOUREXCHANGESERVER/EWS/Services.wsdl
You should be prompted for credentials. After you enter your credentials you will be presented with the WSDL definition. If it does not present you a WSDL definition that looks like the example below then check with your administrator on credentials or if there are any firewall blocks put in place.
Example (Partial response):
<wsdl:definitions targetNamespace="http://schemas.microsoft.com/exchange/services /2006/messages"><wsdl:types><xs:schema><xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/messages" schemaLocation="messages.xsd"/></xs:schema></wsdl:types>
A great tool I use in analyzing web services is: SOAP-UI by SmartBear

Related

Use PEAR on Fedora

I am attempting to use PEAR to send email on a Fedora server machine and am getting nowhere.
Below is the code I am trying to use. The email authentication settings in the code are not the actual but the info I am using is pulled from my email client config so should work.
I am also trying to get debug info to find out what is happening. Is setting 'debug' to 'true' enough or is something else required? And where can I find the debug log information?
A lot of asks but I hope someone can direct me in the right direction.
I tried PHPMailer as well but no go. I have this sense that some configuration on the machine is blocking...
One more thing, this exact code works on a Ubuntu machine so I know it works. I am trying to move all services from the Ubuntu machine to a Fedora machine.
<?php
require_once "Mail.php";
$from = "demo#demo.com";
$recipients = 'demo#demo.com';
$headers["From"] = $from;
$headers["To"] = 'demo#demo.com';
$headers["Reply-To"] = $from;
$headers["Subject"] = 'Testing';
$headers["MIME-Version"] = "1.0";
$headers["Content-Type"] = "text/html; charset=UTF-8";
$body = 'Testing';
$smtpinfo["host"] = "mail.demo.com";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "demo#demo.com";
$smtpinfo["password"] = "password";
$smtpinfo["debug"] = true;
$mail_object = Mail::factory("smtp", $smtpinfo);
$mail_object->send($recipients, $headers, $body);
if (PEAR::isError($mail_object)) {
$ret['success'] = false;
$ret['msg'] = 'Message delivery failed...';
} else {
$ret['success'] = true;
$ret['msg'] = 'data is valid';
}
return $ret;
?>
Thank you
So, after a few more hours of testing I have resolved the issue. This website provided direction on how to get debug information in the command line.
After testing the PHP code from the command line and confirming that messages can be sent, I attempted to send an email from a web page; which failed to work.
So, now thinking that the issue is likely related to the web server, led me to this question on Stack Overflow . The solution of which resolved the issue immediately. Specifically, doing the following as described in the accepted solution:
$ sestatus -b | grep sendmail
httpd_can_sendmail off
$ restorecon /usr/bin/sendmail
$ setsebool -P httpd_can_sendmail 1
Hope this helps someone else facing the some problem.

How to send parameter with try catch exception in yii2?

I have problem in sending email, looks like our server connection to mail server is unstable, sometimes it successfully sent, but sometimes it's not, it say ssl time out.
So my idea is catch timed out exception and insert in database then I can send later.
But I need to send few parameter with catch exception so I can insert database correctly.
So far what I want is something like this
try{
$message = Yii::$app->mail->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('from#domain.com');
} else {
$message->setFrom(Yii::$app->user->identity->email);
}
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("mymail#gmail.com")
->setSubject('Title 1')
->setHtmlBody("Hi, this is my content to check if registration email successfully sent")
->send();
$mail_from = "no-reply#myweb.com";
$mail_to = "customer#someweb.com";
$content = "here is content of email"
$other = "this other variable";
return 1;
}catch(\Swift_TransportException $e, $mail_from, $mail_to, $content, $other){
//if connection time out or something
$queue = new Queue;
$queue->mail_from = $mail_from;
$queue->mail_to = $mail_to;
$queue->content = $content;
$queue->other = $other;
$queue->fail_reason = $e->getMessage();
$queue->save()
}
but it give me undefined variable $mail_from, $mail_to, and etc
How I can fix my problem?
Thanks in advance.
To fix the undefined variable $mail_from, $mail_to, and etc error it's better to declare the variables outside the try block. Because you're declaring the variables at the end of the try, it fails before these variables are ever initialised.
$mail_from = "no-reply#myweb.com";
$mail_to = "customer#someweb.com";
$content = "here is content of email"
$other = "this other variable";
try {
$message = Yii::$app->mail->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('from#domain.com');
} else {
$message->setFrom(Yii::$app->user->identity->email);
}
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("mymail#gmail.com")
->setSubject('Title 1')
->setHtmlBody("Hi, this is my content to check if registration email successfully sent")
->send();
return 1;
} catch(\Swift_TransportException $e) {
//if connection time out or something
$queue = new Queue;
$queue->mail_from = $mail_from;
$queue->mail_to = $mail_to;
$queue->content = $content;
$queue->other = $other;
$queue->fail_reason = $e->getMessage();
$queue->save()
}
But there are more problems with this code. You're setting the from and to part multiple times. In the if/else you're calling setFrom and then again a few lines later. The same goes for setTo. The last call to the function will overrule the previous set value. So make sure you only call these functions once.

get profile picture from instagram api

I'm trying to get profile pictures using Instagram Api. I tried the following code:
function getpho($userid)
{
$userid = "000000";
$token = "my access token";
$url = "https://api.instagram.com/v1/users/".$userid."/?access_token=".$token;
$get = file_get_contents($url);
$json = json_decode($get);
foreach($json->data as $user)
{
return $user->profile_picture;
}
}
echo getpho($userid);
But this returns a blank page. What is wrong with my code?
try
$json = json_decode($get);
return $json->data->profile_picture;
Probably you're in Sandbox mode.
In this mode you can get media only of users that you've invited (up to 10). They will doesn't receive a notification, but they shall accept the request at this address: https://www.instagram.com/developer/clients/sandbox_invites/
By using this link you can get insta user details :
https://www.instagram.com/username/?__a=1&__d=dis

PHPMailer/SwiftMailer Send Email - Connection could not be established with host smtp.gmail.com

I am trying to send emails via PHP Mailer (upon it not working I also installed and tried Swift Mailer, and am getting the same results).
I can send them using localhost but it ALWAYS goes to spam, which is doing my head in. So I am trying to send it through SMTP through my gmail account, in the hope that this will help authenticate the email.
Here is my code:
function SendMail( $ToEmail, $MessageHTML, $MessageTEXT ) {
require_once ( '../phpmailer/PHPMailerAutoload.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port
$Mail->Username = 'b31tom#gmail.com'; // SMTP account username
$Mail->Password = 'workingpass'; // SMTP account password (IVE TRIED BOTH NORMAL AND APP PASSWORDS)
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'b31tom#gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $ToEmail ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = "Test";
$Mail->AltBody = "Test";
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) { // ADDED - This error checking was missing
return FALSE;
}
else {
return TRUE;
}
}
$ToEmail = 'b31tom#me.com';
$ToName = 'Name';
$Send = SendMail( $ToEmail, $MessageHTML, $MessageTEXT );
if ( $Send ) {
echo "<h2> Sent OK</h2>";
}
else {
echo "<h2> ERROR</h2>";
}
die;
This returns the following error:
2014-12-16 13:17:14 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2014-12-16 13:17:14 SMTP connect() failed.
ERROR
I have contacted my web provider to check the following:
OpenSSL enabled
fopen enabled
ports 465 and 587 open
I have gone through numerous example codes from both PHP Mailer and Swift Mailer (which all claim to be working code!) and all give the same result. Normally the error 101 cannot connect to the gmail server!
I currently have a support ticket open with my web provider and have people looking into it there and they can't see an issue either.
Help please :(
Right at this moment, gmail smtp servers appear to be having widespread outages this morning. I don't know code:) but was searching for others having issues. Re-try later.
Thanks for your help. My web provider enabled the pfsockopen function in a local php.ini and it fixed the issue.
I hope this helps any one in the future.

HTML5 localStorage + Twitter oAuth

I have a jQuery Mobile app that uses Twitter oAuth to handle login and registration. However iPhone Mobile apps that get added to the home screen doesn't handle sessions. I have been told I need to use localStorage. Here is my current code that I need help translating to localStorage rather than sessions. Any help would be much appreciated.
Main page:
<?php
require("lib/twitteroauth.php");
session_start();
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('consumer key','secret');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('login.php');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
if($twitteroauth->http_code==200){
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
header ('Location: '.$url);
} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
die('Something wrong happened.');
}
?>
After Twitter handles the login it redirects to login.php:
<?php
require("lib/twitteroauth.php");
session_start();
if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){
// TwitterOAuth instance, with two new parameters we got in twitter_login.php
$twitteroauth = new TwitterOAuth("consumer key", "secret",$_SESSION['oauth_token'],$_SESSION['oauth_token_secret']);
// Let's request the access token
$access_token = $twitteroauth->getAccessToken($_GET['oauth_verifier']);
// Save it in a session var
$_SESSION['access_token'] = $access_token;
// Let's get the user's info
$user_info = $twitteroauth->get('account/verify_credentials');
}
?>
Thanks!
This should help understand what you need to complete the task of saving to LocalStorage.
http://sixrevisions.com/web-development/html5-iphone-app/
nb: see section near end of the article on Offline Data