tryingtolearn Posted December 11, 2009 Share Posted December 11, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/184819-pear-mail-with-attachment-sends-file-name-in-the-attachment/ Share on other sites More sharing options...
tryingtolearn Posted December 11, 2009 Author Share Posted December 11, 2009 Hmmmm well it seems changing $mime->addAttachment ($file, $content_type, $file_name, 1); to $mime->addAttachment ($file, $content_type); solves it but no idea why Quote Link to comment https://forums.phpfreaks.com/topic/184819-pear-mail-with-attachment-sends-file-name-in-the-attachment/#findComment-975694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.