Here is my current code:
mysql_connect ('localhost', 'password', 'theif');
mysql_select_db ('database');
set_time_limit(2500); // Number of seconds before the script time out
ignore_user_abort (0); // The script will keep running even if the user aborts
// Get new messages from mail box
$link = imap_open("{mail.domainname.com}INBOX", 'password', 'theif') or die('Can\'t open mailbox');
$headers = imap_headers($link) or die('Can\'t get headers, or no headers');
// Set the loop up, add 1 to the $headers because of PHP counting issues
for ($currentmail = 1; $currentmail < count($headers)+1; $currentmail++)
{
// Get the bulk header for the EMail
$header = imap_header($link, $currentmail) or die("Can't get header for message $currentmail");
// Parse the header down into indiviual fields
$unix_ts = trim($header->udate);
$subject = trim($header->subject);
$sender = trim($header->fromaddress);
$body = imap_body($link, $currentmail);
echo $body;
// Insert the data into the database
$query = "INSERT INTO EMails VALUES ('$subject', '$sender', '$body')";
mysql_query($query);
}
[/SIZE]So that is my code. The problem is at the $body part.. my script is returning too much crap (Content type) with the $body.. Heres an example of the stuff I am getting..
------=_NextPart_001_0027_01C31328.10EF6590
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
This is the body!Get more from the Web. FREE MSN Explorer download : htt=
p://explorer.msn.com
------=_NextPart_001_0027_01C31328.10EF6590
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<HTML><BODY STYLE=3D"font:10pt verdana; border:none;"><DIV>This is the bo=
dy!<BR><BR></DIV></BODY></HTML><br clear=3Dall><hr>Get more from the Web.=
FREE MSN Explorer download : <a href=3D'http://explorer.msn.com'>http:/=
/explorer.msn.com</a><br></p>
------=NextPart_001_0027_01C31328.10EF6590--
Microsofts blatant advertisment and HTML tags arent the problem but the
------=NextPart_001_0027_01C31328.10EF6590
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
stuff like that is! I need a way for it not to come with the $body. I know you can do this with imap_fetchbody or something, I just cant figure out how to remove that stuff.. and since every mail server will send different formatted stuff, I cant really use string replace functions...
And another thing, why is it randomly adding '=' signs to $body?
Any ideas?