I'm accessing a mailbox using ddeboer/imap. Connecting to the Server and retrieving Messages ist not a problem. But $message->getHeaders() returns the following (shortened Version):
Ddeboer\Imap\Message\Headers Object
(
[storage:ArrayIterator:private] => Array
(
[date] => Fri, 5 Jul 2019 07:00:47 +0200
[subject] => Test Mail
[message_id] => <108a4850-284e-170a-2c7d-b6f9g5218202#test.de>
[fromaddress] => "Test" <test#test.de>
[from] => Array
(
[0] => stdClass Object
(
[personal] => Test
[mailbox] => test
[host] => test.de
)
)
[deleted] =>
[draft] =>
[msgno] => 1
[maildate] => 5-Jul-2019 07:00:49 +0200
[size] => 223715
[udate] => 1562302849
)
)
How am I supposed to access the Information e.g. udate or from->mailbox?
You can use the get method and add the path
$message->getHeaders()->get('udate'):
$message->getHeaders()->get('from')[0]->mailbox
Related
Okay.. I did a lot of research but I kept getting errors so I decided to ask the question directly..
I always converted objects to arrays, but I now want to try using an object directly to save website speed.. I got this object:
stdClass Object
(
[date] => Wed, 8 Feb 2017 15:03:44 +0000
[Date] => Wed, 8 Feb 2017 15:03:44 +0000
[subject] => asdasdasd
[Subject] => asdasdasd
[message_id] =>
[toaddress] => "test#hotmail.com"
[to] => Array
(
[0] => stdClass Object
(
[personal] => test#hotmail.com
[mailbox] => test
[host] => hotmail.com
)
)
[fromaddress] => Jason K
[from] => Array
(
[0] => stdClass Object
(
[personal] => Jason K
[mailbox] => JasonK
[host] => hotmail.com
)
)
[reply_toaddress] => Jason K
[reply_to] => Array
(
[0] => stdClass Object
(
[personal] => Jason K
[mailbox] => JasonK
[host] => hotmail.com
)
)
[senderaddress] => Jason K
[sender] => Array
(
[0] => stdClass Object
(
[personal] => Jason K
[mailbox] => JasonK
[host] => hotmail.com
)
)
[Recent] =>
[Unseen] =>
[Flagged] =>
[Answered] =>
[Deleted] =>
[Draft] =>
[Msgno] => 1
[MailDate] => 8-Feb-2017 16:03:25 +0100
[Size] => 7887
[udate] => 1486566205
)
I am trying to get the first date (wed, 8 feb 2017), the from->mailbox and the Size. I managed to get the from->mailbox with this code:
foreach($EmailHeaders->from as $from ){
echo $from->mailbox;
}
But I just cant find out how to obtain the other values aswell.. If i try:
foreach($EmailHeaders as $headers){
echo $headers->date;
}
then it doesnt work... Can anyone explain this to me? Sorry if this is already asked a thousand times before, I just cant figure it out..
check this http://php.net/manual/en/function.get-object-vars.php
var_dump(get_object_vars($EmailHeaders ));
It's simple, you don't have to iterate over the direct properties, just use
$EmailHeaders->date
To get the "date", you just need to use $EmailHeaders->date
You don't need a foreach. It's working for "from" because it contains an array of objects.
You can simply do
$EmailHeaders->date
OR
$EmailHeaders->Date
to get the date from your object.
While iterating through loop, your pointer is already on the date item, so you can't point to date index. It will point to the date index under date item.
Im in the meddle of creating a web app that downloads all the emails using imap library in php but im troubled on which id should i used, This is a sample email header retrieve from a gmail account.
Array
(
[0] => stdClass Object
(
[subject] => test subject
[from] => someone
[to] => enquire#xxxx.com
[date] => 17 Jun 2016 10:33:13 +0900
[message_id] => <08a32A30-C6n7-4A4A-AE91-C35429AF48BA#x2mail.xxxx.com>
[size] => 8460
[uid] => 8645
[msgno] => 8522
[recent] => 0
[flagged] => 0
[answered] => 0
[deleted] => 0
[seen] => 0
[draft] => 0
[udate] => 1466127256
)
)
as you can see above there is a "uid" and "msgno" which should i use?
http://php.net/manual/en/function.imap-uid.php
Here I read: An UID is a unique identifier that will not change over time while a message sequence number may change whenever the content of the mailbox changes.
So, "uid" would probably be better.
This question already has answers here:
Does this SOAP Fault mean what I think it means?
(3 answers)
Closed 8 years ago.
There is nothing too much to write here other than this error message :
SoapFault Object ( [message:protected] => Wrong Version [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\nsoap\phpclient.php [line:protected] => 10 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\wamp\www\nsoap\phpclient.php [line] => 10 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getIMIPremium [1] => Array ( [0] => Array ( [imiPolicy] => Array ( [expiryDate] => 23-09-2013 [imiInsured] => Array ( [item] => Array ( [item] => Array ( [age] => 23 [basicSumInsured] => 33233 [coverRageType] => 12 [dateOfBirth] => 26-09-1986 [preExistingDisease] => no ) ) ) [inceptionDate] => 12-09-2009 [noOfInsured] => 1 [partnerCode] => 2121 [stateCode] => 233 ) ) ) ) ) [1] => Array ( [file] => C:\wamp\www\nsoap\phpclient.php [line] => 10 [function] => getIMIPremium [class] => SoapClient [type] => -> [args] => Array ( [0] => Array ( [imiPolicy] => Array ( [expiryDate] => 23-09-2013 [imiInsured] => Array ( [item] => Array ( [item] => Array ( [age] => 23 [basicSumInsured] => 33233 [coverRageType] => 12 [dateOfBirth] => 26-09-1986 [preExistingDisease] => no ) ) ) [inceptionDate] => 12-09-2009 [noOfInsured] => 1 [partnerCode] => 2121 [stateCode] => 233 ) ) ) ) ) [previous:Exception:private] => [faultstring] => Wrong Version [faultcode] => VersionMismatch [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ [xdebug_message] => ( ! ) SoapFault: Wrong Version in C:\wamp\www\nsoap\phpclient.php on line 10 Call Stack #TimeMemoryFunctionLocation 10.0009674576{main}( )..\phpclient.php:0 20.0704702744SoapClient->getIMIPremium( )..\phpclient.php:10 )
Is it possible that there is an error in the client php code for it ? I have tried NuSoap, but it is also generating error that "Call error: Response not of type text/xml: application/wsdl+xmlHTTP/1.1 200 OK Date: Tue, 17 Sep 2013 16:55:39 GMT Server: Apache/2.2.22 (Win64) PHP/5.3.13 Last-Modified: Tue, 17 Sep 2013 13:18:39 GMT ETag: "a0000000a818c-12e9-4e69428b54054" Accept-Ranges: bytes Content-Length: 4841 Connection: close Content-Type: application/wsdl+xml ".
Do you know any fix for it ?
PHP Code :
<?php
try{
$client = new SoapClient("http://mysite.com/nsoap/IMIPremiumWebService.wsdl");
$args= array("imiPolicy" => array("expiryDate" => "23-09-2013", "imiInsured" =>array("item" => array("item" => array("age"=>'23', "basicSumInsured"=>'33233', "coverRageType"=>'12',"dateOfBirth"=>'26-09-1986',"preExistingDisease" => 'no'))), "inceptionDate"=>"12-09-2009" ,"noOfInsured"=>'1',"partnerCode" => '2121', "stateCode" => '233'));
$something = $client->getIMIPremium($args);
echo $client->responseData;
print_r($something);
}
catch (Exception $e)
{
echo "*****************";
print_r($e);
}
?>
You can find wsdl here (in my question related to NuSOAP:
WSDL Client Not Working
A little bit of googling with that particular error message reveals that it might be related to the Soap server answering in Soap version 1.2, while the default setting in PHP is Soap version 1.1.
Try adding an options array to the SoapClient with array('soap_version'=> SOAP_1_2) as the second parameter (see http://de1.php.net/manual/en/soapclient.soapclient.php for details).
I'm using php imap function imap_header to extract full header and imap_fetch_overview to extract raw header. Both the functions gives me stdClass object and arrays respectively.
I would like to always clean my from and to before further processing. Sometimes a FROM or TO can contain some thing like this,
Test user <test#test.com>
Also currently in my FROM I only see Test User and no email address until I use firebug.
How do I just get the test#test.com from these objects, arrays?
This is the result I get from imap_fetch_overview
Array
(
[0] => stdClass Object
(
[subject] => Testing
[from] => Test User
[to] => testuser2#test.com
[date] => Wed, 17 Apr 2013 18:43:46 +0530
[message_id] => <abcdef1244.93784jgsfk#test.com>
[size] => 3443
[uid] => 1234
[msgno] => 123
[recent] => 0
[flagged] => 0
[answered] => 0
[deleted] => 0
[seen] => 0
[draft] => 0
[udate] => 1366204439
)
)
There is a hidden <test#test.com> next to Test User. How do I extract that email address?
Similarly this is what I get from imap_header
stdClass Object
(
[date] => Wed, 17 Apr 2013 18:43:46 +0530
[Date] => Wed, 17 Apr 2013 18:43:46 +0530
[subject] => Test
[Subject] => Test
[message_id] => <abcdef1244.93784jgsfk#test.com>
[toaddress] => testuser#test.com
[to] => Array
(
[0] => stdClass Object
(
[mailbox] => testuser
[host] => test.com
)
)
[fromaddress] => Test User
[from] => Array
(
[0] => stdClass Object
(
[personal] => Test User
[mailbox] => test
[host] => test.com
)
)
[reply_toaddress] => Test User
[reply_to] => Array
(
[0] => stdClass Object
(
[personal] => Test User
[mailbox] => test
[host] => test.com
)
)
[senderaddress] => Test User
[sender] => Array
(
[0] => stdClass Object
(
[personal] => Test User
[mailbox] => test
[host] => test.com
)
)
[Recent] =>
[Unseen] => U
[Flagged] =>
[Answered] =>
[Deleted] =>
[Draft] =>
[Msgno] => 123
[MailDate] => 17-Apr-2013 13:13:59 +0000
[Size] => 3443
[udate] => 1366204439
)
A preg_match would be the obvious answer but just cant seem to figure out how to perform it on from bit where email address is not seen in the browser but is present when inspected with firebug. Any help is appreciated.
Thanks.
You can go one step further with imap_rfc822_parse_adrlist()Docs:
$toAddresses = imap_rfc822_parse_adrlist('Test user <test#test.com>', 'localhost');
print_r($toAddresses);
Array
(
[0] => stdClass Object
(
[mailbox] => test
[host] => test.com
[personal] => Test user
)
)
If name of array of std object is $arr
$arr[0]->to
returns what you want.
in second case
$stdObject <- object that is returned by second function
foreach($stdObject->to as $to)
{
echo $to->mailbox;
echo $to->host;
}
I've just discovered this thread and whilst it's old I hope this comment might help. I believe I've answered the query. As it happens, the format of the sender email is what's causing the issue.
From Name <from#name.com>
Because of the <> tag, the browser is making it into an HTML tag, I guess something akin to a span. By using str_replace to change "<" into " " (or whatever) you remove the issue before it gets to HTML
I have some XML that is being returned to be as an object, like this:
SwitchvoxResponse Object
(
[apiStatus:private] => success
[apiErrors:private] => Array
(
)
[apiResult:private] => Array
(
[calls] => Array
(
[page_number] => 1
[total_pages] => 1
[items_per_page] => 50
[total_items] => 1
[call] => Array
(
[0] => Array
(
[id] => 14301
[origination] => outgoing
[start_time] => 2011-06-17 13:40:58
[from] => CALLER_NAME <4485>
[from_account_id] => 1120
[from_name] => CALLER_NAME
[from_number] => 4485
[to] => CALLEE_NAME <6534>
[to_account_id] => 1101
[to_name] => CALLEE_NAME
[to_number] => 6534
[total_duration] => 47
[talk_duration] => 43
[events] => Array
(
[event] => Array
(
[0] => Array
(
[start_time] => 2011-06-17 13:40:58
[type] => OUTGOING
[display] => Dialed number (6534)
)
[1] => Array
(
[start_time] => 2011-06-17 13:40:58
[type] => INTERNAL
[display] => Rang CALLEE_NAME <6534>
)
[2] => Array
(
[start_time] => 2011-06-17 13:41:02
[type] => TALKING
[display] => Talked to CALLEE_NAME <6534> for 43 seconds
)
[3] => Array
(
[start_time] => 2011-06-17 13:41:45
[type] => HANGUP
[display] => Call was hung up by CALLER_NAME <4485>
)
)
)
)
)
)
)
)
How do I pull out the values of these variables?
The results can be accessed via the SwitchvoxResponse::getResult() method. Given $object is the SwitchvoxResponse object quoted in the question, the example below loops over each call and prints the from values.
$result = $object->getResult();
foreach ($result['calls']['call'] as $call) {
echo $call['from'];
}
Similarly, the response status is fetched via $object->getResponseStatus() and any errors via $object->getErrors().
The response statuses can be one of SV_RESPONSE_SUCCESS, SV_RESPONSE_FAULT or SV_RESPONSE_FAILED.
Edit re. comments
To get the items for the first call only, simply do:
$result = $object->getResult();
$call = $result['calls']['call'][0];
// And access the values like
echo $call['from_name'];
All three properties are marked private, so they would have to be obtained through accessor methods marked public