RE: [PHP] Save email as .eml file
[snip] Is there a way to create e-mail with PHP and save it to .eml file (without sending)? [/snip] Yes, there is a way. http://www.google.com/search?hl=en&q=save+as+.eml -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
I've been struggling with the same issue, does anyone have a link to or know of a way to automatically create eml files using PHP? The links that Google search returned were mostly specific to email clients, I need to create the eml files on the server. Thanks -- View this message in context: http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11701195 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
Hi there, Well it can be easily done. Just input your mail (make 'procmail' fwd it) to your script & script would save it as .eml . Try to use the following code for script : CODE # Hope this helps you out. Greetings Utsav Handa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
Thanks for your help. How would I go about getting procmail to forward it? What I currently have is a script that connects to a free email address that collects bounces captured from newsletters the system has sent. I'm using IMAP to connect to the mailbox, then looping through and trying to create the eml files. I don't know if the procmail approach would work, as I can only access my email through IMAP (not even POP3). Last night while examining some eml files and cross referencing to the value imap_body returned, I was thinking I may be able to just dump that to a file. Do you think that would work? There's a class on phpclasses that handles bounces, but it requires eml files (http://www.phpclasses.org/browse/package/2691.html). Here is my code as it is now, don't know if that would help or not: ### CODE ### $imap = imap_open("{mail.messagingengine.com:143}INBOX", "**", "**"); $message_count = imap_num_msg($imap); echo "$message_count Emails Returned"; for ($i = 1; $i <= $message_count; ++$i) { $header = imap_header($imap, $i); if (isset($header->from[0]->personal)) { $personal = $header->from[0]->personal; } else { $personal = $header->from[0]->mailbox; } $eml = "date : $header->Date \n"; $eml .= "from : $personal <{$header->from[0]->[EMAIL PROTECTED]>from[0]->host}> \n"; $eml .= "subject : $header->Subject \n"; $eml .= "to : $personal <{$header->to[0]->[EMAIL PROTECTED]>from[0]->host}> \n"; $eml .= imap_body($imap, $i, "FT_PEEK")."\n"; $messageID = imap_bodystruct($imap, $i, "message_id"); echo "header"; print_r($header); echo ""; echo "Body"; print_r(imap_body($imap, $i, "FT_PEEK")); echo ""; $file = "../eml/".rand(, ).".eml"; if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; } if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; } echo "You have successfully written data to $file"; fclose($file_handle); } imap_close($imap); Thanks, Bobby Handa Utsav wrote: > > Hi there, > > Well it can be easily done. Just input your mail (make 'procmail' fwd > it) to your script & script would save it as .eml . > > Try to use the following code for script : > > CODE # > > > $email = ""; > ## Read > E-mail > > $fd = fopen("php://stdin", "r"); > while (!feof($fd)) { > $email .= fread($fd, 1024); > } > fclose($fd); > > # Save email > $handle = fopen("$path/$file_name.eml","a+"); > if (!$handle) { >fwrite($log_handle," Failed "); > } > else { >fwrite($handle,"$email"); >fclose($handle); > } > > > ?> > > Hope this helps you out. > > > Greetings > Utsav Handa > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- View this message in context: http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11712721 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
I think I found a solution. Must admit I feel pretty down for spending so much time on this when the solution was so simple, but I couldn't find too much info on PHP's imap functions. Hopefully this will be indexed and help developers in the future. PHP has a function that saves the message in a valid RFC1892 multipart report format: $res = imap_savebody($imap, "../eml/test.eml", 2); Thank you all for your help! -- View this message in context: http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11714301 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
On Wed, July 18, 2007 8:56 am, Rosen wrote: > Is there a way to create e-mail with PHP and save it to .eml file > (without sending)? I dunno if MS adds anything funky to a .eml file, but I suspect that it's just the raw headers and then the body... So pretty much file_put_contents would do it, if you can forge a halfway-reasonable set of headers. Open up an .eml file in a text editor and see what it looks like. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
On Thu, July 19, 2007 9:18 pm, bkozora wrote: > I've been struggling with the same issue, does anyone have a link to > or know > of a way to automatically create eml files using PHP? The links that > Google > search returned were mostly specific to email clients, I need to > create the > eml files on the server. Thanks The original Google link posted, admittedly, did not actually have any useful results in the first page. Googling for "php .eml file" however, yielded this in the top 10: http://www.phpclasses.org/discuss/package/9/thread/1/ I don't think it can get any easier or more clear than that, frankly... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
What exactly is the end goal after you have the message in an ".eml" file? If you just fetch the WHOLE damn thing with IMAP and dump it into a file and name it "whatever.eml" then you're done, by the way. So imap_fetchheader, find out how many body parts there are, imap_fetchbody for each one, dump all that crap into a file and put a fork in it. On Fri, July 20, 2007 12:43 pm, bkozora wrote: > > Thanks for your help. How would I go about getting procmail to forward > it? > > What I currently have is a script that connects to a free email > address that > collects bounces captured from newsletters the system has sent. I'm > using > IMAP to connect to the mailbox, then looping through and trying to > create > the eml files. I don't know if the procmail approach would work, as I > can > only access my email through IMAP (not even POP3). > > Last night while examining some eml files and cross referencing to the > value > imap_body returned, I was thinking I may be able to just dump that to > a > file. Do you think that would work? There's a class on phpclasses that > handles bounces, but it requires eml files > (http://www.phpclasses.org/browse/package/2691.html). > > Here is my code as it is now, don't know if that would help or not: > > ### CODE ### > > $imap = imap_open("{mail.messagingengine.com:143}INBOX", "**", "**"); > > $message_count = imap_num_msg($imap); > > echo "$message_count Emails Returned"; > > > for ($i = 1; $i <= $message_count; ++$i) > { > $header = imap_header($imap, $i); > > if (isset($header->from[0]->personal)) > { > $personal = $header->from[0]->personal; > } > else > { > $personal = $header->from[0]->mailbox; > } > > $eml = "date : $header->Date \n"; > $eml .= "from : $personal > <{$header->from[0]->[EMAIL PROTECTED]>from[0]->host}> \n"; > $eml .= "subject : $header->Subject \n"; > $eml .= "to : $personal > <{$header->to[0]->[EMAIL PROTECTED]>from[0]->host}> \n"; > > $eml .= imap_body($imap, $i, "FT_PEEK")."\n"; > > $messageID = imap_bodystruct($imap, $i, "message_id"); > > echo "header"; > print_r($header); > echo ""; > > echo "Body"; > print_r(imap_body($imap, $i, "FT_PEEK")); > echo ""; > > $file = "../eml/".rand(, ).".eml"; > if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; } > if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; } > echo "You have successfully written data to $file"; > fclose($file_handle); > > } > > > imap_close($imap); > > > > Thanks, > Bobby > > > Handa Utsav wrote: >> >> Hi there, >> >> Well it can be easily done. Just input your mail (make 'procmail' >> fwd >> it) to your script & script would save it as .eml . >> >> Try to use the following code for script : >> >> CODE # >> >> > >> $email = ""; >> ## Read >> E-mail >> $fd = fopen("php://stdin", "r"); >> while (!feof($fd)) { >> $email .= fread($fd, 1024); >> } >> fclose($fd); >> >> # Save email >> $handle = fopen("$path/$file_name.eml","a+"); >> if (!$handle) { >>fwrite($log_handle," Failed "); >> } >> else { >>fwrite($handle,"$email"); >>fclose($handle); >> } >> >> >> ?> >> >> Hope this helps you out. >> >> >> Greetings >> Utsav Handa >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> > > -- > View this message in context: > http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11712721 > Sent from the PHP - General mailing list archive at Nabble.com. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Save email as .eml file
Yeah, that and imap_savebody($imap, $fn, $i); work. Thanks Richard Lynch wrote: > > On Wed, July 18, 2007 8:56 am, Rosen wrote: >> Is there a way to create e-mail with PHP and save it to .eml file >> (without sending)? > > I dunno if MS adds anything funky to a .eml file, but I suspect that > it's just the raw headers and then the body... > > So pretty much file_put_contents would do it, if you can forge a > halfway-reasonable set of headers. > > Open up an .eml file in a text editor and see what it looks like. > > -- > Some people have a "gift" link here. > Know what I want? > I want you to buy a CD from some indie artist. > http://cdbaby.com/browse/from/lynch > Yeah, I get a buck. So? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- View this message in context: http://www.nabble.com/Save-email-as-.eml-file-tf4103444.html#a11719234 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php