+2 votes
50 views

Hello!

I am making an application in flutter that allows to check the emails of my imap mailbox. The verification is done through a PHP code. So far everything is correct. I've been seeing the PHP imap_search () statement that allows searching in the body, in the header and in the subject (and various other places). Apparently everything works correctly, but I have verified that the searches ARE NOT correct. For example, if I want to search my emails for a date "2020-03-05" it does it correctly, but if I also have the word "success" in the same email, it would also give me the correct search if I searched for "2020-03- success". In other words, when they put hyphens it does NOT do the exact search, what it does is to search the emails for the number "2020", the number "03", and the word "success", and if it finds them even if they are not together " 2020-03-success "will show the search as correct when it obviously is not.

I wish they could help me.

Greetings.

Code Example

<?php

$numbersOfEmail = 0;
$rutaImap = "{example.myserver.com:993/imap/ssl/novalidate-cert}INBOX";
$usuarioImap = "myuser@mydomain.com";
$claveImap = "myPassword";

$inbox = imap_open($rutaImap,usuarioImap,claveImap) or die( json_encode(array("Resultado" => $numbersOfEmail, "Estado" => "Fail")));

$cadenaCero = "2000-03-25";

$query1 = sprintf(' BODY "%s" ', $cadenaCero);

$emails = imap_search($inbox, $query1);

if($emails) {

  $numbersOfEmail = count($emails);

}

imap_close($inbox);
echo json_encode(array("resultado" => $numbersOfEmail, "estado" => "OK"));

?>
by   | 50 views
hi antonio!
plz keep visiting on your question's page, I shall give a proper solution here as soon as i can.

1 Answer

0 votes

Hi Antonio!

EDIT: there is also an error in your imap_open function. you have used some keywords instead of variables. You have used imap_open($rutaImap,usuarioImap,claveImap) please change it to imap_open($rutaImap,$usuarioImap,$claveImap)

Changed code is here

<?php

$numbersOfEmail = 0;
$rutaImap = "{example.myserver.com:993/imap/ssl/novalidate-cert}INBOX";
$usuarioImap = "myuser@mydomain.com";
$claveImap = "myPassword";

$inbox = imap_open($rutaImap,$usuarioImap,$claveImap) or die( json_encode(array("Resultado" => $numbersOfEmail, "Estado" => "Fail")));

$cadenaCero = "25-March-2000";

$query1 = sprintf(' BODY "%s" ', $cadenaCero);

$emails = imap_search($inbox, $query1);

if($emails) {

  $numbersOfEmail = count($emails);

}

imap_close($inbox);
echo json_encode(array("resultado" => $numbersOfEmail, "estado" => "OK"));

?>

Here is the working output of your code image.png

by (3.1k points)  
edited by
Thank you for you response. This is not solution. I want search in Body exact phrase.

The example I put may not be very illustrative. Imagine that I want to search "car in my house", exactly. Well, if in the same email the different words exist separately, even if they are not together, it will also answer that the exact phrase is there. I think it is quite rare, and either I am not understanding it correctly, or imap_search does not work correctly.
Please check again! I have edited my answer

Related questions

+1 vote
1 answer
+2 votes
0 answers
asked Jun 20 by athar (3.1k points) | 13 views
+3 votes
1 answer
asked Jun 19 by athar (3.1k points) | 13 views
+2 votes
0 answers
+2 votes
0 answers
+1 vote
0 answers




Welcome to Meansflow - Where Developers and Students Learn, Share, & Build Careers, where you can ask questions and receive answers from other members of the community.
113 questions
85 answers
38 comments
103 users