Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Sending a text/PHP file

the mail() function

Moderators: macek, egami, gesf

Sending a text/PHP file

Postby Martin Pickering » Mon Apr 19, 2004 2:15 pm

I want to pick up a PHP file from my server as two separate text files, add the web page visitor's email address into the string, then send it to him.

I can already do this but the string arrives in the body of the message whereas I want it to arrive as an attachment and preferably with the filename "email.php".

Is it a simple matter of changing the header or am I out of my depth?

I can get it to arrive as an HTML attachment but that's not what I want and it has the filename "Enclosed.html" when my email client receives it.

Here's the script which achieves that so far. I've omitted the obvious parts:

Code: Select all
<?php
// Set headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/txt; charset=iso-8859-1\r\n";

$f = "part1.txt";
$g = "part2.txt";

// Get text files
$part1 = implode('',file($f));
$part2 = implode('',file($g));

//Add files together with email address in place
$note = $part1 . $MFrom . $part2;

// And this is the actual email and the function to send it
mail($MFrom,$MailSubject,"

$note

","From: someone@somewhere.com" . "\r\n"  . $headers . "\r\n");

?>

Finished


Help/corrections would be very much appreciated.

Martin Pickering (UK)
Martin Pickering
New php-forum User
New php-forum User
 
Posts: 106
Joined: Fri Oct 17, 2003 8:00 am

Postby Martin Pickering » Mon Apr 19, 2004 3:02 pm

OK, I've read this:

http://www.php-forum.com/p/viewtopic.php?t=579

..but I don't fully understand it.

It makes me wonder, however, if I should be saving the string as a file (how?) in order to send it as an attachment (how?)

Martin Pickering (UK)

My powers are limited. I can unscramble a satellite broadcast but I can't unscramble an egg.
Martin Pickering
New php-forum User
New php-forum User
 
Posts: 106
Joined: Fri Oct 17, 2003 8:00 am

Postby Martin Pickering » Wed Apr 21, 2004 2:12 am

Martin Pickering
New php-forum User
New php-forum User
 
Posts: 106
Joined: Fri Oct 17, 2003 8:00 am

phpmailer class

Postby ruturajv » Thu Apr 22, 2004 7:55 pm

take a look at this

http://phpmailer.sourceforge.net

it has solved lot of problems.
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby Martin Pickering » Fri Apr 23, 2004 12:59 am

Thanks. In fact the "hollowearth" page was exactly what I needed. It was so close that all I had to do was copy/paste it and change a couple of variables to suit my needs. I'm now able to send an email with two attachments. :)

Martin Pickering (UK)
Martin Pickering
New php-forum User
New php-forum User
 
Posts: 106
Joined: Fri Oct 17, 2003 8:00 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron