John Davidson

imap with curl on php

0 comments
Message:


I have created a very simple function:


function send($command) {
$url = 'imaps://myImapServer';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, 993);
curl_setopt($ch, CURLOPT_USERNAME, "MyUsername");
curl_setopt($ch, CURLOPT_PASSWORD, "MyPassword");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $command);

$res = curl_exec($ch);

return $res;
}

I can use it to query folders, but also, for example, the UID of all my messages:


echo send('UID SEARCH ALL');
# Output: * SEARCH 63 64 65 66

But for two problems I dont find a solution.



  • How do I create an array HTML Body, Text Body, Reply to,... from my outputs?



  • Why do I get the lenght of the subject with the following query, but the subject itself is not displayed?


    echo send('UID FETCH 63 BODY[HEADER.FIELDS (SUBJECT)]');
    Output: * 1 FETCH (UID 63 BODY[HEADER.FIELDS (SUBJECT)] {29}





My Answer:
'username@example.com');_ curl_setopt($ch, CURLOPT_PASSWORD, 'password');_ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $command);_ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);_ $response = curl_exec($ch);_ curl_close($ch);_ return $response;_}_// Example usage:echo send('LIST'); // List all mailboxesecho send('FETCH 1 BODY[]'); // Fetch the body of the first email

Rate this post

5 of 5 based on 2052 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us