0

Hello i have read all related topics and found some solution about how to get loop but and certain value but still can not get value from subarray [tracking] from array below:

[26] =>
 Array ( [id] => ab94b21221379be8231250962f51073d
 [sender] => [email protected] 
[total_size] => 776 
[sender_ip] => 173.212.205.208 [smtp_answer_code] => 250 [smtp_answer_code_explain] => Delivered [smtp_answer_subcode] => [smtp_answer_data] => [email protected] H=gmail-smtp-in.l.google.com [173.194.69.26] X=TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128 CV=yes K C="250 2.0.0 OK z58si11170265edc.200 - gsmtp" 
[used_ip] => 78.41.200.159
 [recipient] => [email protected]
 [subject] => Mail subject
 [send_date] => 2017-06-26 09:49:48
 [tracking] =>
            Array ( 
[click] => 0 
[open] => 1 
[client_info] => 
             Array ( [0] => Array ( [browser] => Firefox 11.0viaggpht.comGoo[os] => Windows [ip] => 11.111.93.76 [country] => United States [action_date] => 2017-03-27 07:59:46 ) ) ) )

I have used standart loop to get value [open] = 1, but got Undefined index: open error message from debugger. Yes i got undefined index because i cannot get tracking value as subarray. It always asked in loop no matter of the type for i=1;i=k;i++ or foreach $array as $key=>$value.

1
  • add a tag for the programming lang Commented Jul 10, 2017 at 14:39

4 Answers 4

0

You can use isset['open'] to check either "open" index set or not.

You can use isset operator inside the loop:

foreach($array as $value)
{
      if(isset($value['tracking']['open']))
      {
          echo $value['tracking']['open'];
      }
}
Sign up to request clarification or add additional context in comments.

1 Comment

ok. I have tried with !is_null() but cannnot get 'open' item with '$c=count($smtpcheck); for ( $i=0; $i < $c; $i++){ if(!is_null($smtpcheck[$i]['tracking']['open'])) { echo $smtpcheck['tracking']['open']; } break;} it echo an : Undefined index though i am really sure that array have only 3 levels between desirable variable: index of array, value and subarray value.
0

You have echo incorrect value... try
if(isset($smtpcheck[$i]['tracking']['open'])) {
echo $smtpcheck[$i]['tracking']['open'];
}

3 Comments

I have corrected values but got no result. Some time were needed to rebuild loop removing i++ method and switched several times to !is_empty() as my server deprecated few weeks ago isset function. So now got it work.
Topic can be closed.
working sample of code thanks again to Verma Kshitij here github.com/Dignity1988/sendpulse/blob/master/book1.php
0

I have finally stopped with following code:

$opened=array();

/*First step:set the array we will use for our "subarray" or child array Second step loop through main array it finally save results of main array values within working loop. Add condition for subarray values that they are equal to 1 and already set. So we don't need to modify php.ini and select lower level of notice warnings which means that recipient is opened the mail.

*/
foreach  ($smtpcheck as $sendstatus=>$value){
     if (isset($value['tracking']) and $value['tracking']['open']=='1')
     { 
       $opened=$value['recipient']);// And finally printing the certain main array(one level higher but still binded to the main loop) and printing them
print_r($opened);
 }

I have finally got the list of all recipients which are opened email. Thanks @Kshitij Verma for the good advice in correct time and place. I have explored almost all similar questions to answer and got the code above to work. I would be impossible without you. Still i found no option to print nor save all subarray "tracking" but got another idea with "switch" function for it. @Kshitij Verma you may write me in private.I Think i should add the credentials to the git project i am working on.

Comments

0
foreach ($smtpcheck as $sendstatus=>$value){
if (isset( $value['smtp_answer_code'] ) ){
switch ($sendstatus = substr($value['smtp_answer_code'], 0, 1)){
case "0": print_r('No message status is already fired but to early to ask status');break;
case "1": print_r('deliverance is on the go, brothers and sisters');print_r('onthego->'); array_push($onthego,$value['recipient']);print_r($onthego);
break;
case "2":
//check if value of open state of switcher is "opened"
//check second layer of delivery to get exact knowledge of what we fucking got
//check next if value of open state switcher is "cliked
if (isset($value['tracking']) and $value['tracking']['open']=='1' and  $value['tracking']['click']=='0'){;array_push($openedbutnotclicked, $value['recipient']);print_r('--openedbutnotclicked=>');print_r($openedbutnotclicked);break;}
if (isset($value['tracking']) and $value['tracking']['open']=='0' and  $value['tracking']['click']=='0'){;array_push($delivered, $value['recipient']);print_r('delivered');print_r($delivered);break;}
if (isset($value['tracking']) and $value['tracking']['click']=='1'){
array_push($clicked, $value['recipient']);print_r($cliked);break;
}
case "3": print_r ('ok fine but please fill up additional fields like DATA because server requires the additional information and/or redirected your email');print_r('--not enough credentials=>');array_push($userinfo,$value['recipient']);print_r($userinfo);break;
case "4": print_r ('check the credentials');print_r('--invalid email check the credentials=>');array_push($broken, $value['recipient']);
break;
case "5": print_r('--notreached->');array_push($blocked, $value['recipient']);print_r($blocked);break;
}
}

Here what i got after several experiments. The main array "smtpcheck" contains 3 level depth subarrays and dismounted to the arrays.

};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.