I have a e-mail driver. It get a list of e-mail accounts and receive and store messages, it works fine. But the messages deletion, at last line, doesn't works. Thats a part of code:
$arrPop3Config['host'] = $arrEmailconfiguracao['strPOPHost'];
$arrPop3Config['port'] = $arrEmailconfiguracao['intPOPPorta'];
$arrPop3Config['user'] = $arrEmailconfiguracao['strPOPUsuario'];
$arrPop3Config['password'] = $arrEmailconfiguracao['strPOPSenha'];
if($arrEmailconfiguracao['intAuth'] == '1') {
$arrPop3Config['ssl'] = 'SSL';
} else if($arrEmailconfiguracao['intAuth'] == '2') {
$arrPop3Config['ssl'] = 'TLS';
}
$objMail = new Zend_Mail_Storage_Pop3($arrPop3Config);
foreach($objMail as $intMensagemNum => $objMensagem) {
$strMensagemUniqueId = $objMail->getUniqueId($intMensagemNum);
$arrHeader = $objMensagem->getHeaders();
$strRemetente = $objMensagem->getHeader('from', 'string');
preg_match_all("/(.*)?<(.*)?>/", $strRemetente, $arrRemetente);
$strRemetenteNome = $arrRemetente[1][0];
$strRemetenteEmail = $arrRemetente[2][0];
$strTitulo = $objMensagem->getHeader('subject', 'string');
$objMensagemPart = $objMensagem;
while ($objMensagemPart->isMultipart()) {
$objMensagemPart = $objMensagem->getPart(1);
}
$strCorpo = $objMensagemPart->getContent();
$objDb->call(
'emailClienteRecebe'
,array(
'intEmailconfiguracao' => $arrEmailconfiguracao['intId']
,'strMensagemUniqueId' => $strMensagemUniqueId
,'strRemetenteNome' => $strRemetenteNome
,'strRemetenteEmail' => $strRemetenteEmail
,'strHeaders' => serialize($arrHeader)
,'strTitulo' => $strTitulo
,'strCorpo' => $strCorpo
)
);
$objMail->removeMessage($strMensagemUniqueId);
Php client return this message:
PHP Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'last request failed' in /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php:189
Stack trace:
#0 /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php(221): Zend_Mail_Protocol_Pop3->readResponse(false)
#1 /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php(457): Zend_Mail_Protocol_Pop3->request('DELE GmailId12d...')
#2 /var/www/maru/Maru/Zend/Mail/Storage/Pop3.php(227): Zend_Mail_Protocol_Pop3->delete('GmailId12de8345...')
#3 /var/www/maru/drivers/recebe-emails/driver.php(82): Zend_Mail_Storage_Pop3->removeMessage('GmailId12de8345...')
#4 {main}
thrown in /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php on line 189
Apparently the pop command "DELE GmailId1283038051edcc6e" is the problem. However, using a common e-mail client, like mozilla thunderbird, i've monitorated sent commands e the same command works fine.
Any ideas?
I know nothing about the Zend Pop3 client, only by looking at the online documentation.
The POP3 specification has a DELE command, taking a message number. You are supplying a string!
Therefore the server of course does not know what to do. The Zend POP3 method even states that the id supplied has to be of integer type in the removeMessage documentation.
If you look at the getNumberByUniqueId documentation, you will see that you should translate the unique ID to a message number before calling removeMessage.
Therefore, to fix your problem, you should replace your last line with:
$objMail->removeMessage($objMail->getNumberByUniqueId($strMensagemUniqueId));
And then I think everything will be fine.
Related
I am trying to integrate google sheets api with php so that I can capture html form data and append it to spreadsheet but I am facing a weird error.
Below is the php snippet:
$client = new \Google_Client();
$client->setApplicationName('WEBMONK_QUOTATION_REQUESTS');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig('../credentials.json');
$service = new Google_Service_Sheets($client);
$spreadsheets_id = '1S2LPDl5XmOEx4TQ3cR4yZ4SAALcxXRyxU5nFMU7RW0I';
$range = 'QUOTESHEET';
$sheet_rows = [
strval($datetime),
strval($name),
strval($email),
strval($url),
strval($extras)
];
$body = new Google_Service_Sheets_ValueRange(['values' => [$sheet_rows]]);
$params = ['valueInputOption' => 'RAW'];
$insert = ['insertDataOption' => 'INSERT_ROWS'];
$result = $service->spreadsheets_values->append(
$spreadsheets_id,
$range,
$body,
$params,
$insert
);
Here is the error I am getting:
<br />
<b>Fatal error</b>: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php:291
Stack trace:
#0 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(291): implode(Array, '&')
#1 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(190): Google_Service_Resource->createRequestUri('v4/spreadsheets...', Array)
#2 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient-services\src\Google\Service\Sheets\Resource\SpreadsheetsValues.php(64): Google_Service_Resource->call('append', Array, 'Google_Service_...')
#3 C:\xampp\htdocs\webric.org\api\post\insert.php(68): Google_Service_Sheets_Resource_SpreadsheetsValues->append('1S2LPDl5XmOEx4T...', 'QUOTESHEET', Object(Google_Service_Sheets_ValueRange), Array, Array)
#4 {main}
thrown in <b>C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php</b> on line <b>291</b><br />
So far, that I have understood, an implode() function in the Google lib is malfunctioning because of wrong argument type. But I couldn't find anything wrong with my above php code. I have gone through the google sheets and php integration procedures as mentioned here:
PHP with Google Sheets Quickstart
PHP version: 8.0.0,
Google API Client: 2.0
Please tell me where I am going wrong. Thanks in advance.
Just had the same issue after switching to PHP 8.0 (previously working fine with PHP 7.2).
The implode() function in PHP 8.0 has basically the two arguments switched compared to previous versions. I checked out the lastest version of the Resource.php file in the Google library, and you should see that the line 303 reflects those changes already.
I went to my Resource.php file and replaced
$requestUrl .= '?' . implode($queryVars, '&');
with
$requestUrl .= '?' . implode('&', $queryVars);
And it's working again. Hope it helped!
There must be a problem with your values
Verify it by modifying $body to
$body = new Google_Service_Sheets_ValueRange([
"values" => [[1, 2, 3]]
]);
If this request works for you - log [$sheet_rows] to compare the structure and see what is wrong.
PS: Apart from the Quickstart, there is aslo method specific documentation for PHP
A password was changed and cPanel broke. Fixed the password and it's still broken! I have to iterate over parked domains. I've verified the user / password combination is correct via PuTTY.
<?php
include_once('cpanel_api_xml.php');
$domain = 'example.com';
$pass = '';//etc
$user = '';//etc
$xmlapi = new xmlapi('127.0.0.1');
$xmlapi->password_auth($user,$pass);
$domains_parked = $xmlapi->listparkeddomains($user);
foreach ($domains_parked as $k1=>$v1)
{
if ($v1->domain == $domain) {$return = true; break;}
}
?>
That code generates the following error:
Invalid argument supplied for foreach()
Apparently $domains_parked is not even set! I've spent time looking at the function being called so without dumping all 86KB here is the cleaned up version of $xmlapi->listparkeddomains:
<?php
public function listparkeddomains($username, $domain = null)
{
$args = array();
if (!isset($username))
{
error_log("listparkeddomains requires that a user is passed to it");
return false;
}
if (isset($domain))
{
$args['regex'] = $domain;
return $this->api2_query($username, 'Park', 'listparkeddomains', $args);
}
return $this->api2_query($username, 'Park', 'listparkeddomains');
}
?>
I don't know what they're doing with setting a variable as the second parameter. I've called this function with and without and tested the reaction with a simple mail().
Next I tried calling the API in a more direct fashion:
$xmlapi->api2_query($username, 'Park', 'listparkeddomains')
That also does not work. Okay, let's try some really raw output testing:
echo "1:\n";
print_r($xmlapi);
echo "2:\n";
print_r($xmlapi->api2_query($user, 'Park', 'listparkeddomains'));
echo "3:\n";
$domains_parked = $xmlapi->listparkeddomains($user);
print_r($domains_parked);
die();
That outputs the following:
1: xmlapi Object (
[debug:xmlapi:private] =>
[host:xmlapi:private] => 127.0.0.1
[port:xmlapi:private] => 4099
[protocol:xmlapi:private] => https
[output:xmlapi:private] => simplexml
[auth_type:xmlapi:private] => pass
[auth:xmlapi:private] => <pass>
[user:xmlapi:private] => <user>
[http_client:xmlapi:private] => curl ) 2: 3:
I have never encountered such fragile code though I have no choice but to use it. Some help please?
So cPanel version 74 killed off the whole XML API and it doesn't frigin tell you with any error messages. I can not objectively say in the least that cPanel provides a stable platform to build anything reliable upon. You can either intentionally gimp your server from automatically updating (and potentially miss out on security updates) or every so X iterations of time completely rewrite the code again...and again...and again.
I have the following code
//$sp = new SharePointAPI('&&', '&&', 'https://&&.net/personal/zzz/_vti_bin/Lists.asmx?WSDL',);
//$sp = new SharePointAPI('&&', '&&', 'https://&&net/personal/zzz/_vti_bin/Lists.asmx?SDL', 'NTLM');
$sp = new SharePointAPI('&&', '&&', 'https://&&net/personal/zzz/_vti_bin/Lists.asmx?WSDL', 'SPONLINE');
$listContents = $sp->read('GetListCollection');
return $listContents;
Depending on which of the "new SharepointAPI" lines I execute, I get a different error.
Using "NTLM", I get the error: -
Uncaught exception 'Exception' with message 'Error'
in /home/shinksyc/public_html/sharepointUpload/src/Thybag/Auth/SoapClientAuth.php:129
Stack trace:
#0 [internal function]: Thybag\Auth\SoapClientAuth->__doRequest('<?xml
version="...', 'https://my.sp.m...', 'http://schemas....', 1, 0)
Using "SPONLINE", I get the error
'Error (Client) looks like we got no XML document'.
I am also slightly confused as to how to find out what the name of the lists may be that I get read.
Any help is much appreciated.
Thanks
Martin
The path to your xml must be local: in clear, log to your sharepoint, go to the url https://mySPsite/subsite/_vti_bin/Lists.asmx?WSDL
Download the XML and place it on your PHP server.
then
$sp = new SharePointAPI($login, $password, $localPathToWSDL, 'NTLM');
I'm using the Solr PHP Client and have the Solr 4.3.0 example up and running. I have not modified the schema.xml file. When I run this code I get a 400 error:
Uncaught exception 'Apache_Solr_HttpTransportException' with message '400' Status: Bad Request.'
The document does not show up in the index. Interestingly, If I restart Jetty, the document is indexed. Here's my code. I was wondering if I'm missing something. I thought this was an issue with my input matching the schema, but id seems to be the only required field and these other fields are in the schema. I'm not sure what to do.
require_once('SolrPhpClient/Apache/Solr/Service.php');
$solr = new Apache_Solr_Service('localhost', 8983, '/solr/');
if($solr->ping() == null){
die('could not ping solr');
}
$document = new Apache_Solr_Document();
$document->id = 'guid1';
$document->title = 'Title1';
$document->subject = 'The subject is solr';
$document->description = 'This is the description';
$solr->addDocument($document);
$solr->commit();
The full error message I get is
Fatal error: Uncaught exception 'Apache_Solr_HttpTransportException' with message ''400' Status: Bad Request' in C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php:364
Stack trace:
#0 C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php(829): Apache_Solr_Service->_sendRawPost('http://localhos...', '<commit expunge...', 3600)
#1 C:\xampp\htdocs\dev\indexerSOLR_PHP.php(20): Apache_Solr_Service->commit()
#2 {main} thrown in C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php on line 364`
This is a known issue with Solr 4.x and calling commit from the Solr PHP Client. Please see
Bug #62332 - As of solr 4.0 the waitFlush parameter is removed for commit for the details and a patch to fix the issue.
That is what how I got the solution, I modified commit method. Added '&commit=true' to the _updateurl variable.
public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
{
$expungeValue = $expungeDeletes ? 'true' : 'false';
$flushValue = $waitFlush ? 'true' : 'false';
$searcherValue = $waitSearcher ? 'true' : 'false';
//$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
//$this->post=$rawPost;
return $this->_sendRawGet($this->_updateUrl.'&commit=true', $timeout);
}
You have change this line.
require_once('SolrPhpClient/Apache/Solr/Service.php'); => require_once('Service.php');
Maybe Service.php this file's path wrong. I try to changed this line. Then work successfully.
I had the same issue because I have installed an old version of the PHP Solr extension (0.9.11).
To get a the latest one:
pecl download solr-beta
tar xvzf solr-2.1.0.tgz # This can be different depending on the last release number
cd solr-2.1.0/
phpize
./configure
make
sudo make install
# add extension=solr.so to your php.ini / distribution extension loader
Thanks to this post.
I want to display my public fanpage feed onto my website via the Facebook API without requiring a login.
I'm doing this
require_once('../includes/classes/facebook-platform/php/facebook.php');
$fb = new Facebook($api_key, $secret);
$fb->api_client->stream_get('',$app_id,'0','0','','','','',''));
But I get this error
Fatal error: Uncaught exception 'FacebookRestClientException' with message 'user id parameter or session key required' in includes/classes/facebook-platform/php/facebookapi_php5_restlib.php:3065
Stack trace:
#0 includes/classes/facebook-platform/php/facebookapi_php5_restlib.php(1915): FacebookRestClient->call_method('facebook.stream...', Array)
#1 facebook/api.php(12): FacebookRestClient->stream_get('', 13156929019, '0', '0', 30, '', '', '', '')
#2 {main}
thrown in includes/classes/facebook-platform/php/facebookapi_php5_restlib.php on line 3065
Then I figured, because of 'user id parameter or session key required', to add my user id to the call
require_once('../includes/classes/facebook-platform/php/facebook.php');
$fb = new Facebook($api_key, $secret);
$fb->api_client->stream_get(502945616,13156929019,$app_id,'0','0','','','','',''));
But then I got this error
Fatal error: Uncaught exception 'FacebookRestClientException' with message 'Session key invalid or no longer valid'
I'm totally clueless :)
Here's what i did
1) Login to facebook.
2) Grant your application offline access to your account:
http://m.facebook.com/authorize.php?api_key=YOUR_API_KEY&v=1.0&ext_perm=offline_access
3) Add read stream permission
http://m.facebook.com/authorize.php?api_key=YOUR_API_KEY&v=1.0&ext_perm=read_stream
4) Generate a key code
http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY
5) Run this script once and copy the "session_key".
$facebook = new Facebook($api_key, $api_secret);
$infinite_key = $facebook->api_client->auth_getSession(YOUR_KEY_CODE);
print_r($infinite_key);
6) Plug and play!
$facebook->api_client->user = YOUR_FACEBOOK_USER_ID
$facebook->api_client->session_key = YOUR_INFINITE_KEY
$facebook->api_client->expires = 0;
$feed = $facebook->api_client->stream_get(YOUR_FACEBOOK_USER_ID, FAN_PAGE_ID);
So bascially, this will grab the feed from your "perspective" but filter it only to show items from the specified Fan page.
Disclaimer: This works, but I'm not sure whether this is a "supported" method for grabbing data, or even allowed at all.
References:
http://www.emcro.com/blog/2009/01/facebook-infinite-session-keys-no-more/
http://blog.jylin.com/2009/10/01/loading-wall-posts-using-facebookstream_get/
Ok, I tried many times, but it worked when I added QUOTES to code.
$infinite_key = $facebook->api_client->auth_getSession('YOUR_KEY_CODE');
Thanks for suggestion!
You need the Facebook library in your code and it is better to say APP_ID not API_KEY.
<?php
require_once('facebook.php');
$facebook = new Facebook('YOUR_APP_ID', 'YOUR_APP_SECRET');
$infinite_key = $facebook->api_client->auth_getSession('YOUR_KEY_CODE');
print_r($infinite_key);
?>