Jump to content

PEAR mail with attachment sends file name in the attachment


tryingtolearn

Recommended Posts

Hi all,

Cant seem to figure where Im going wrong.

I have a form that writes the input to a .csv file

That works.

Then I wanted the form with the data to be sent to an email address as an attachment.

The problem is the data in the .csv is overwritten by the file name ($file)

 

so instead of the .csv being filled w/ the form data - A1 simply has the name of the .csv file instead)

Any ideas?

 

[Things I already tried -

Not having the file name - didnt send an attachment

Changing the content type between application/vnd.ms-excel and text/csv - no difference - got the file name both times]

$classmail=array(''.$posted.','.$site.'');
	$fp = fopen('file.csv', 'a+');
foreach ($classmail as $line) {
    fputcsv($fp, explode(",", $line));
}
fclose($fp);

//construct eMail
include('Mail.php');
include('Mail/mime.php');
        $sender = "classMail Info <[email protected]>";
        $recipient = "JOE <[email protected]>";
        $subject = "classMail Spreadsheet";
        $text = 'Here is your updated classMail spreadsheet.';
        $html = '<html><body><p><b>Here is your updated classMail spreadsheet.</b></p></body></html>';
        $crlf = "\n";
        $headers = array(
                        'From'          => $sender,
                        'Return-Path'   => $sender,
                        'Subject'       => $subject 
                        );

        // Creating the Mime message
        $mime = new Mail_mime($crlf);

        // Setting the body of the email
        $mime->setTXTBody($text);
        $mime->setHTMLBody($html);

        // Add an attachment
        $file = "file.csv";                                       
        $file_name = "file.csv";                                  
        $content_type = "application/vnd.ms-excel";                          
        $mime->addAttachment ($file, $content_type, $file_name, 1);  
        $body = $mime->get();
        $headers = $mime->headers($headers);

        // Sending the email
        $mail =& Mail::factory('mail');
        $mail->send($recipient, $headers, $body);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.