Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

Wwwxxxapc, CAM::PDF::Renderer::TextF Fragen, adodb.recordset error '800a0cc1', php save mails as eml, WWWXXXAPC, sqlexpress database file auto-creation error, sqlexpress database file auto-creation error, dbf2mysql parameter, wwwxxxAPC, How to unsubscrube from dategen spam

Links

XODOX
Impressum

#1: Save email as .eml file

Posted on 2007-07-18 15:56:07 by Rosen Marinov

Hi,
Is there a way to create e-mail with PHP and save it to .eml file
(without sending)?

Thanks,
Rosen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#2: RE: Save email as .eml file

Posted on 2007-07-18 16:06:03 by Jay Blanchard

[snip]
Is there a way to create e-mail with PHP and save it to .eml file=20
(without sending)?
[/snip]

Yes, there is a way. =
http://www.google.com/search?hl=3Den&q=3Dsave+as+.eml

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#3: Re: Save email as .eml file

Posted on 2007-07-20 04:18:09 by bkozora

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

Report this message

#4: Re: Save email as .eml file

Posted on 2007-07-20 06:16:43 by Handa Utsav

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 #####################

<?php

$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

Report this message

#5: Re: Save email as .eml file

Posted on 2007-07-20 19:43:02 by bkozora

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 "<h3>$message_count Emails Returned</h3>";


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]->mailbox}@{$header->from[0]->host}> \n";
$eml .= "subject : $header->Subject \n";
$eml .= "to : $personal
<{$header->to[0]->mailbox}@{$header->from[0]->host}> \n";

$eml .= imap_body($imap, $i, "FT_PEEK")."\n";

$messageID = imap_bodystruct($imap, $i, "message_id");

echo "<h3>header</h3><pre style=\"color:red;\">";
print_r($header);
echo "</pre>";

echo "<h3>Body</h3><pre style=\"color:red;\">";
print_r(imap_body($imap, $i, "FT_PEEK"));
echo "</pre>";

$file = "../eml/".rand(1111, 9999).".eml";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; }
echo "<h4>You have successfully written data to $file</h4>";
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 #####################
>
> <?php
>
> $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

Report this message

#6: Re: Save email as .eml file

Posted on 2007-07-20 21:12:55 by bkozora

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

Report this message

#7: Re: Save email as .eml file

Posted on 2007-07-21 01:20:50 by Richard Lynch

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

Report this message

#8: Re: Save email as .eml file

Posted on 2007-07-21 01:25:29 by Richard Lynch

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

Report this message

#9: Re: Save email as .eml file

Posted on 2007-07-21 01:30:09 by Richard Lynch

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 "<h3>$message_count Emails Returned</h3>";
>
>
> 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]->mailbox}@{$header->from[0]->host}> \n";
> $eml .= "subject : $header->Subject \n";
> $eml .= "to : $personal
> <{$header->to[0]->mailbox}@{$header->from[0]->host}> \n";
>
> $eml .= imap_body($imap, $i, "FT_PEEK")."\n";
>
> $messageID = imap_bodystruct($imap, $i, "message_id");
>
> echo "<h3>header</h3><pre style=\"color:red;\">";
> print_r($header);
> echo "</pre>";
>
> echo "<h3>Body</h3><pre style=\"color:red;\">";
> print_r(imap_body($imap, $i, "FT_PEEK"));
> echo "</pre>";
>
> $file = "../eml/".rand(1111, 9999).".eml";
> if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
> if (!fwrite($file_handle, $eml)) { echo "Cannot write to file"; }
> echo "<h4>You have successfully written data to $file</h4>";
> 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 #####################
>>
>> <?php
>>
>> $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

Report this message

#10: Re: Save email as .eml file

Posted on 2007-07-21 05:54:09 by bkozora

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

Report this message

#11: Re: Save email as .eml file

Posted on 2007-07-21 21:20:02 by Manuel Lemos

Hello,

on 07/18/2007 10:56 AM Rosen said the following:
> Hi,
> Is there a way to create e-mail with PHP and save it to .eml file
> (without sending)?

You can use the GetMessage function of this class. It can compose
messages like you want, and then it can return the composed message in
..eml format as a text string.

http://www.phpclasses.org/mimemessage


--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message