Jump to content

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.