1

I have been developing CRM for lead management, now i want to get a selected lead emails from my email by ID.

I use php imap function to get all the emails from the mail server, but in this scenario i can't pull out particular email conversations by its ID.

Here is my code:

function imap_email_list_by_lead_email_id($inbox,$lead_email,$company_email)
{  
  $emails_sorted_1 = imap_search($inbox,'FROM '.$company_email,'TO '.$lead_email);
  $emails_sorted_2 = imap_search($inbox,'FROM '.$lead_email, 'TO '.$company_email);

  $lead_converstion_msg_no = array_merge($emails_sorted_1,$emails_sorted_2);


  $mail_list_contents = array();

  for ($i=0; $i < count($lead_converstion_msg_no); $i++) { 
    $mail_content = imap_fetch_overview($inbox,$lead_converstion_msg_no[$i]);

    $mail_list_contents[] = $mail_content;
  }

  $results = array_reverse($mail_list_contents);
  return $results;

} 

I hope, i will find an answer here.

Eibs
  • 86
  • 8
  • What results do you get? How many search results do you get? This is a great place to add some debug output so you can see where it breaks down. – Max Jun 10 '20 at 14:25
  • it returns empty array – Eibs Jun 11 '20 at 06:33
  • Which does? Are all of $email_sorted_1, $email_sorted_2 and $lead_conversation_msg_no all empty? What do your searches look like? Have you printed out the email addresses? We can't help you without you doing some debugging on your end, telling us your inputs, and showing us your outputs. – Max Jun 11 '20 at 14:18
  • Thanks Sir @Max ,Now I have get emails from particular email id, using imap_search($inbox,"FROM xxx@email.com "); AND imap_search($inbox, "TO xxx@email.com); i just pass same email id in from and to, now its working sir, now i need another help, which is i have use imap_open at one time for getting all subjects via imap_fetch_overview(), and using the same imap stream i want to get a each subject messages using imap_fetch_body(), i try to use this but it will get only a first msg_no message body other msg_no return empty!.. can you assist me sir.. – Eibs Jun 12 '20 at 05:40

0 Answers0