473,776 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve and save mail attachtments with PHP

Hi,

I made a funstion that checks a mail account, retrieves and stores the
attachments in a folder on my website.

This works great for .doc files but not for .pdf files.

I am almost sure the problem is in: $fileContent =
imap_base64($fi leContent);

Whet is the encoding for PDF attachments ?

Can someone help me with this.

Best Regards,

JAKE, Belgium

This is the script (copied the function in a standalone script, the only
thing this does is open pop account, check messages, store attachments,
close imap connection):

<?php
$login = 'mypoplogin';
$password = 'mypoppassword' ;
$mbox = imap_open("{127 .0.0.1:110/pop3/notls}INBOX", "$login", "$password" )
or die("Could not open Mailbox - try again later!");
//
// make connection with mailbox and check # messages
if ($hdr = imap_check($mbo x)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>" ;
$msgCount = $hdr->Nmsgs;
} else { echo "failed"; }
$overview=imap_ fetch_overview( $mbox,"1:$msgCo unt",0);
$size=sizeof($o verview);

// get message info
for($i=$size-1;$i>=0;$i--)
{
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;
$from = ereg_replace("\ "","",$from );

// Check for attachements and store them
$struct = imap_fetchstruc ture($mbox,$msg );
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($ix=2;$ix<=$co ntentParts;$ix+ +) {
$att[$ix-2] = imap_bodystruct ($mbox,$msg,$ix );
}
for ($k=0;$k<sizeof ($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" ||
$att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$FileName[$k] = $att[$k]->parameters[1]->value;
$FileType[$k] = strrev(substr(s trrev($FileName[$k]),0,4));
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" &&
$att[$k]->parameters[0]->value != "ISO-8859-1") {
$FileName[$k] = $att[$k]->parameters[0]->value;
$FileType[$k] = strrev(substr(s trrev($FileName[$k]),0,4));
$fileContent = imap_fetchbody( $mbox,$msg,$fil e+2);
$fileContent = imap_base64($fi leContent);

$localfile = fopen("/var/www/html/storedattachmen ts/$FileName[$k]","w");
fputs($localfil e,$fileContent) ;
fclose($localfi le);
}
}
}
}
imap_close($mbo x);
?>
Aug 7 '05 #1
1 1818
*** JAKE wrote/escribió (Sun, 07 Aug 2005 14:31:07 GMT):
I am almost sure the problem is in: $fileContent =
imap_base64($fi leContent);

Whet is the encoding for PDF attachments ?


Mail encoding does not depend on file contents, which is obviously a good
thing: imagine you could only attach and receive files your mail client is
coded for!

Main point: what does "doesn't work" mean for you?
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Aug 8 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12361
by: Didier FRAISSE | last post by:
i need to retrieve every day an email and to save his attachments for later processing. i found some piece of code in the documentation like import poplib pop = poplib.POP3(Host) pop.user(User) pop.pass(Pwd) nbMsg, nbOctet = pop.stat() for n in range(nbMsg):
0
1831
by: John Dalberg | last post by:
Mail component to retrieve mail from Hotmail, Yahoo, gmail..etc? I am not sure these web based mail support POP3 or IMAP4. Is there any mail component out there that can retrieve mail from these services? -- John Dalberg
3
2154
by: Stefano | last post by:
I've a form windows with a lot of textbox controls. How can I do if I have to save all text proprety of this controls in an external file, to reload them in future?
4
6264
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
13
2205
by: no.mail.pls | last post by:
Hiya, How do i retreive fields with similar values from 2 tables? I tried to use (1) "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like '%p.name%'"; but it retrieves nothing at all. (2) "SELECT * FROM $table1 as o , $table2 as p WHERE o.name like p.name";
0
1480
by: Hexman | last post by:
Hello All, Its a bit more complicated than the subject line implies. A website that I use for information allows me to click on a link and their .PDF displays in IE's browser window.. Since this data has a life-span of about a week (replaced by a newer updated one on a daily basis) and if I happen to miss a day viewing and recording the info I want, its gone forever. To solve this problem, I wrote a small app to retrieve their index...
6
2809
by: Watermark | last post by:
i got problem with this i m implementing web based mail system. i want to access mbox and retrieve mail from it and display it on web page.. can anybody help me.
11
3731
by: subhadip | last post by:
Hi , I want to retrieve any web page content using javascript . suppose I logged into my gmail account and opened my e-mail. now i want that a javascript will execute on the page and read all text content from that page (e.g. all email subjects ) and save it in a text file . I may embed the script in my browser. Is this possible ? Can you suggest any code for this ? Thank you . Regards Subhadip
1
1554
by: ASPLearner | last post by:
Hi, I am trying to retrieve contect from other website and save it to database. Anyone can help? For Example: I want my script go to a webpage and retrieve someone's first name, last name & address automatically. After I get the details, I want to save to my database. Can I do something like this? Thanks in advance!
0
9627
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9462
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10060
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9922
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7469
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5367
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4030
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3621
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.