Re: File attachment to mail() doesn't work....
| From: | Marek Kilimajer | Date: | Sat, 18 Oct 2003 01:01:02 +0000 |
| Subject: | Re: File attachment to mail() doesn't work.... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-166577@lists.php.net to get a copy of this message | ||
I don't have the will to look into your code but why don't you use a class to send out the mail. That's what I always do.
Scott Fletcher wrote:
Hi Fellas!I already whipped up the script to get the PHP mail() to send an emailwith body text, along with the file attachment. Still haven't got this to work right. If I omit out the attachment feature then the mail() work successfully and I receive an email with body message successfully. But with attachment, I'm able to get the mail to be send successfully but I receive email without body text and without attachment. I have been looking around on the Internet for guidance and tweak my php script, but so far no luck. So, can anyone look into it and correct it for me? --snip--$pdf_filename=date("Y_m_d_H_i_s")."_Invoice.pdf"; $pdf_filepath="pdf_archive/".$pdf_filename;$fp = fopen($pdf_filepath, 'rb'); $pdf_raw_data = fread ($fp, filesize($pdf_filepath)); fclose ($fp);$EmailMsg = "--0-1076063429-1066421657=:70798"; $EmailMsg .= "Content-Type: text/plain; chrset=us-ascii"; $EmailMsg .= "Content-Id:"; $EmailMsg .= "Content-Disposition: inline"; $EmailMsg .= "\n\tDate:\t\t".date("F d, Y @ g:i:s A"); $EmailMsg .= "\n\n\t(( Text Message ))\n"; $EmailMsg .= "\n\n\t========= Enclosed PDF File ========="; $EmailMsg .= "\n\tAttached File:\t".trim($pdf_filename); $EmailMsg .= "\n\n\t(( Base64 Message [PDF File] ))"; $EmailMsg .= "\n\n--0-1076063429-1066421657=:70798"; $EmailMsg .= "Content-Type: application/pdf;name='".trim($pdf_filename)."'";$EmailMsg .= "Content-Transfer-Encoding: base64"; $EmailMsg .= "Content-Description: ".trim($pdf_filename)."'"; $EmailMsg .= "Content-Disposition: attachment;filename='".trim($pdf_filename)."'";$EmailMsg .= $pdf_raw_data; $EmailMsg .= "--0-1076063429-1066421657=:70798";$MARKET_Subject = "Invoice Statement"; $MARKET_Message = $EmailMsg; $MARKET_To = "whoami@whoami.com"; $MARKET_From = "whoami@whoami.com";$MARKET_Header = "From: ".$MARKET_From."\r\n"; $MARKET_Header .= "Return-Path: ".$MARKET_From."\r\n"; $MARKET_Header .= "Error-To: ".$MARKET_From."\r\n"; $MARKET_Header .= "MIME-Version: 1.0\r\n"; //$MARKET_Header .= "Content-Type: text/plain;charset=iso-8859-1\r\n";$MARKET_Header .= "Content-Type: multipart/mixed;boundary='0-1076063429-1066421657=:70798\r\n";$MARKET_Header .= "X-Priority: 3\r\n"; $MARKET_Header .= "X-MSMail-Priority: Normal\r\n"; $MARKET_Header .= "X-Mailer: PHP ".phpversion()."\r\n";if(mail($MARKET_To,$MARKET_Subject,$MARKET_Message,$MARKET_Header,"-f$MARKET _From")){ $email_status = "E-Mail was successfully send!!"; } else { $email_status = "E-Mail failed to be send!! (Failed)"; } echo $email_status;--snip-- Thanks a million! Scott F.