IMAP map_search() for ics files - php

i wants to fetch email having only .ics files using IMAP in php
$emails = imap_search($inbox, 'ALL');
i am using above code for search i need some condition instead of "All" or imap_search by some extension(.ics) which gives me emails having .ics

you ccan used this function to serach the perticular extation in your email.
<?php $keyword=".ics";
$emails = imap_search($inbox,'BODY "'.$keyword.'"', SE_FREE, "UTF-8");
?>

The search key header content-disposition ".ics" may or may not work. Depends on the server.
IMAP isn't quite well defined in this aspect.
HEADER <field-name> <string>
Messages that have a header with the specified field-name (as
defined in [RFC-2822]) and that contains the specified string
in the text of the header (what comes after the colon). If the
string to search is zero-length, this matches all messages that
have a header line with the specified field-name regardless of
the contents.
So the field name has to be as defined in 2822. But email messages contain three kinds of header (the top-level message header, embedded message/822 headers and finally bodypart headers), and all three use that syntax. I suspect that most servers search either the first kind of header or all three, and that the RFC's author had in mind the first two.
So why don't you just try the search key with the target server, and if it works, it works.

Thanks you friends i got the exact solution of my problem
i am opening connection first by imap_open then searching emails
$imap_search($inbox, 'ALL')
then fetching structure of emails by imap_fetchstructure and from that structure i am getting ics files from attachments and finally form attachments i am getting imap body imap_base64(imap_fetchbody($mbox, $mid, 2));
it will gives me actually .ics calendar content

Related

PHP prepare MAILTO with HTML

Im looking for a solution, to prepare a complete email for opening with a mail client
PHP is used for generating the link.
Here is the usefull part of my code.
$body = str_repalace('&amp','%26',$body);
$mailtarget = "mailto:".$adress."?cc=".$ccs."&Subject=".rawurlencode($subject)."&Body=".$body.
header("Location = $mailtarget");
This solution works fine, unless i use html in the mail, which is necessary (<br>,<hr>, <table>.
If used HTML sometimes nothing gets in Body, and sometimes just a part of the text.
When I mail the HTML with sendmail.exe, it works perfect. But this is not an option, since its required to add attachments manually to the mail.
Is there any way, to get this properly to work?
It's not possible to include HTML in body's mailto.
You can try to url_encode your HTML and set it as body in your mailto link, but it has a lot of risks of not working in many email clients.
From this answer, it's even defined in the RFC 2368 :
The special hname "body" indicates that the associated hvalue is the
body of the message. The "body" hname should contain the content for
the first text/plain body part of the message. The mailto URL is
primarily intended for generation of short text messages that are
actually the content of automatic processing (such as "subscribe"
messages for mailing lists), not general MIME bodies.
Try: &Body=".urlencode($body);
Use rawurlencode function to insert carriage return :
<?php
$body = '
First line
Second line';
header("location: mailto:emailadresse#domain.com?subject=Hello&body=".rawurlencode($body));
?>

When to use imap_qprint?

I'm using PHP's IMAP Functions extension to check e-mail from a POP3 account.
When it comes to actually fetching the message, I have the following code:
// Make new raw email message
// With PHP Imap, we need to fetch headers and body separately!
$body = imap_fetchheader($mailbox, $msgno);
$body .= imap_qprint(imap_body($mailbox, $msgno));
All the examples I am able to find mentions that one should use imap_qprint() here, but I've noticed that when I do all the GET parameters of a URI get mangled.
For example,
http://localhost/pronk.php?id=6248&key=c7eb7c5173e1525a47c63abc39d938e1
becomes:
http://localhost/pronk.php?idb48&keyƇeb7c5173e1525a47c63abc39d938e1
If I don't use imap_qprint() everything seems to work just fine. (I'm using imap_body instead of imap_fetch_body because I want the entire e-mail - headers, parts, and everything) But since all examples I can find say to use qprint, I wanted to know why my code seems to need it omitted?
Not sure if you're still curious about this, but if you do want to use imap_qprint(), you need to first check what the encoding of the message is.
You can do this using imap_fetchstructure(). http://php.net/manual/en/function.imap-fetchstructure.php.
Only if the encoding is set to 'QUOTED-PRINTABLE' would you want to use imap_qprint().

Processing html mail using phpmailer mail->Body fetching mail body using imap_fetchbody

Okay. So what i did was that i retrieved the body of an email using imap_fetchbody and forward the contents in it to another user's email using mail->Body.
The following are the 2 different formats of the mail i get from different settings:
eg1:
mail->isHtml(true);
eg2:
mail->isHtml(false);
The result i want to have is eg2 but i need to insert html code into the mail itself hence i cannot have mail->isHtml(false), i need it to be true. I'm not sure why this is happening but i realize that the cause in difference in formatting is due to this mail->isHtm() property.
What can i do?
Any help here will be greatly appreciated.

How to show Embedded image in an HTML email as normal images (PHP)

I am creating an email client and going through many problems. Now the latest problem which I am facing is to show embedded images on the HTML email body.
My email body code looks similar to this:
<img alt="image001" src="cid:image001.gif#01CCB988.809DD560" id="Picture_x0020_1" />
Few related posts are found, but they are not useful. Also looking for other possible similar problems while displaying mail contents.
I am using PHP IMAP with POP3 to fetch mails. Currently using gmail as mail server. Sending mails using SMTP (PhpMailer).
Thanks in advance.
In HTML, images are standalones documents with a specific URI (used by src="" attribute).
In your MIME boby, this src attribute refer to a relative MIME part.
So, you'll need to write all MIME parts contents in a distinct file (i.e. /tmp/[md5_MIME_PART_ID])
Then use a CGI script to rewrite the email body and forward specific mime request :
readmail.php
<?
if($_GET['mime']) {
readfile("/tmp/{$_GET['mime']}");
die;
}
$contents = preg_replace("/sid:/", "readmail.php?mime=$1", $contents);
echo $contents;
Of course, a proper database system will be more efficient here, but that's a start
Did you use:
$mail->AddEmbeddedImage(filename, cid, name);
//By using this function with this example's value above, results in this code:
$mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg ');
If yes, what is going wrong? Why are you not happy.
Please note that by default, most email clients do not show embedded images, this is goes for Gmail and Outlook. You can not circumvent that. Its a security / bandwith saving feature. The user would first have to press 'Show images' before they appear.

block sending emails that are not from a specific domain

I would like to filter emails sent. Emails are sent with the PHP mail() function. I would like, without modifying any PHP file if possible, to let emails out only emails that are to a specific domain, and not others. I don't have access to the SMTP server.
Just in case this helps someone ... If the emails are sent after a form is submitted (or similar action), you could change the action attribute of the form html element to point to a new php file that acts as a filter. Once passed (if so) you redirect to the "proper" destination to send the emails. The filtering could be something as easy as:
$good = "*#mydomain.foo, *#localhost";
$good = explode(',', $good);
if (pattern_grep($_POST['email'], $good)) {
// action
}
You should be able to look at the associative array for the "to" field and use the php regex class to match domains that you blacklist.

Categories