p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

pro_php thread: PRO PHP EMAIL PROGRAM

Message #1 by cullan.crothers@w... on Thu, 22 Feb 2001 23:00:03
Dear Sirs:

I am working in the Profesional PHP Programming Book in Chapter 17 with 
emails. I can get the add attachment example to work fine, but when I try 
the add multiple attachments (all files of type in a directory) I get 
various errors. Namely CGI program did not return proper HTTP headers and 
memory referenced cannot be read. Is there something I am missing in IIS 
maybe. I feel it has something to do with my content-types registered in 
IIS. What is different in content-type from the first (single attachment 
file) example to the next with multiple attachments? Do I need to register 
another content-type listing in IIS? If so, what kind? Please let me know 
if you have any answers. The examples are on pages 445-449 in the book.
------->>>>>>>>>Here is my file (not including the include file 


include "mime_mail.inc";

# check whether the user has already submitted an address
if (empty($recipient)) {

   Please enter your e-mail address to receive the files:

      <INPUT TYPE="text" NAME="recipient">
      <INPUT TYPE="submit" VALUE=" OK ">


print "Sending files to $recipient.<p>";

# set up $mail object
$mail = new mime_mail;

$mail->from    = "cullan.crothers@w...";
$mail->to      = $recipient;
$mail->subject = "Your files";
$mail->body    = "Hello, here are your files.";

$content_type = "text/html";

# open current directory and search for files ending with .jpg

$dir = opendir(".");                               # "." is the name of 
the current directory
while ($filename = readdir($dir)) 
//if(ereg("\.htm$", $filename))
      $fd = fopen($filename, "r");
      $data = fread($fd, filesize($filename));

    $mail->add_attachment($data, $filename, $content_type);

     print "I've added $filename.<br>";

# send e-mail

print "I've sent off the e-mail.";


I have filetypes in IIS that account for Content-Type html(.htm 
and .html) , Content-Type XML(.xml and .xsl), Content-Type image/jpeg(.jpg 
and .jpeg), etc.

See what you can make of it.


Cullan Crothers

  Return to Index