dwayne80 Posted August 25, 2007 Share Posted August 25, 2007 Hoi mensen, ik probeer een xml bestand als bijlage te versturen via php zijn mail() functie. Echter kom ik er niet helemaal uit. De mail wordt verstuurd maar het bevat geen body en tevens ook geen bijlage. Gewoon een blanko email. De code ziet er als volgt uit. <?php $to = '[email protected]'; $subject = "test mail"; $random_hash = md5(date('r', time())); $headers = "From: [email protected]\r\nReply-To: [email protected]"; $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"MIXED-".$random_hash."\""; $headers .= "\r\ncharset=\"iso-8859-1\""; $attachment = chunk_split(base64_encode(file_get_contents('test.xml'))); $body = "--MIXED-".$random_hash." \n Content-Type: multipart/alternative; boundary=\"ALT-".$random_hash."\" \n --ALT-".$random_hash." \n Content-Type: text/html; charset=\"iso-8859-1\" \n Content-Transfer-Encoding: quoted-printable \n <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <HTML><HEAD> <META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" > </HEAD> <BODY bgColor=\"#ffffff\"> <P>Geachte test persoon,<BR><BR> In de bijlage treft u het xml bestand. </P> <P>Vriendelijk gegroet<BR> Dwayne</P> <P> </P> <P><FONT face=\"Arial\" size=\"2\">Niemansweg 100<BR> 1000AA Amsterdam<BR><BR> Tel:020-1234567<BR> Fax:020-1234567<BR> E-mail:[email protected]</FONT></P> </BODY> </HTML> \n --ALT-".$random_hash."\n --MIXED-".$random_hash."\n Content-Type: text/xml; name=\"test.xml\" \n Content-Transfer-Encoding: base64 \n Content-Disposition: attachment; filename=\"test.xml\" \n ".$attachment." \n --MIXED-".$random_hash."--"; mail( $to, $subject, $body, $headers ); ?> Kan iemand hier toevallig naar kijken en mij laten weten wat ik hier precies fout doe? Alvast bedankt voor de tijd. Groetjes Dwayne Link to comment https://forums.phpfreaks.com/topic/66597-emailing-with-attachment/ Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 Im guessing it is netherlands from the .nl domain. Any english?? Link to comment https://forums.phpfreaks.com/topic/66597-emailing-with-attachment/#findComment-333653 Share on other sites More sharing options...
dwayne80 Posted August 25, 2007 Author Share Posted August 25, 2007 sorry forgot that i had to post in english I am trying to email an xml file as an attachment to an html email via the mail() function in PHP. Sadly though I am rather stumped. I've been looking at it over and over and basically not showing any progress. The mail is being sent per say but only with a title. No Body. Just a blanc empty email void of any attachments. Here is the code I had written thus far. <?php $to = '[email protected]'; $subject = "test mail"; $random_hash = md5(date('r', time())); $headers = "From: [email protected]\r\nReply-To: [email protected]"; $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"MIXED-".$random_hash."\""; $headers .= "\r\ncharset=\"iso-8859-1\""; $attachment = chunk_split(base64_encode(file_get_contents('test.xml'))); $body = "--MIXED-".$random_hash." \n Content-Type: multipart/alternative; boundary=\"ALT-".$random_hash."\" \n --ALT-".$random_hash." \n Content-Type: text/html; charset=\"iso-8859-1\" \n Content-Transfer-Encoding: quoted-printable \n <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <HTML><HEAD> <META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" > </HEAD> <BODY bgColor=\"#ffffff\"> <P>Dear xyz,<BR><BR> In the attachment you will find the xml file. </P> <P>Kind Regards<BR> Dwayne</P> <P> </P> <P><FONT face=\"Arial\" size=\"2\">Someroad 100<BR> 1000AA Amsterdam<BR><BR> Tel:020-1234567<BR> Fax:020-1234567<BR> E-mail:[email protected]</FONT></P> </BODY> </HTML> \n --ALT-".$random_hash."\n --MIXED-".$random_hash."\n Content-Type: text/xml; name=\"test.xml\" \n Content-Transfer-Encoding: base64 \n Content-Disposition: attachment; filename=\"test.xml\" \n ".$attachment." \n --MIXED-".$random_hash."--"; mail( $to, $subject, $body, $headers ); ?> Can anyone take a look at this and inform me what exactly i'm doing wrong here. I know there are other workable ways like the xpertmailer class or using PEAR but i fail to see how this isn't working. Thanks in advance Dwayne Link to comment https://forums.phpfreaks.com/topic/66597-emailing-with-attachment/#findComment-333660 Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 Shouldn't u have the attached file in the headers? Link to comment https://forums.phpfreaks.com/topic/66597-emailing-with-attachment/#findComment-333674 Share on other sites More sharing options...
dwayne80 Posted August 25, 2007 Author Share Posted August 25, 2007 Not as far as i can tell. Sending an email to myself at work and then checking the headers, i get the following Return-Path: <[email protected]> Delivered-To: [email protected] Received: (qmail 42819 invoked from network); 25 Aug 2007 06:54:29 +0200 Received: from mail04.unet.nl (84.53.82.13) by dedicated1.aqua-it.com with SMTP; 25 Aug 2007 06:54:29 +0200 Received: from DESIGNER (84-53-78-6.wxdsl.nl [84.53.78.6]) by mail04.unet.nl (Postfix) with SMTP id 624715806E1 for <[email protected]>; Sat, 25 Aug 2007 06:54:34 +0200 (CEST) Message-ID: <012001c7e6d4$09332330$6501a8c0@DESIGNER> Reply-To: "Dwayne Roberts" <[email protected]> From: "Dwayne Roberts" <[email protected]> To: <[email protected]> Subject: test Date: Sat, 25 Aug 2007 06:54:36 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 Disposition-Notification-To: "Dwayne Roberts" <[email protected]> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-Antivirus: AVG for E-mail 7.5.484 [269.12.4/969] Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_011D_01C7E6E4.CCAD9B50" Those are the headers and this is the body. ------=_NextPart_000_011D_01C7E6E4.CCAD9B50 Content-Type: text/plain; format=flowed; charset=iso-8859-1; reply-type=original Content-Transfer-Encoding: 7bit This is a test! ------=_NextPart_000_011D_01C7E6E4.CCAD9B50 Content-Type: text/xml; name=test.xml Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="aanvraag03.xml" <?xml version=3D"1.0" encoding=3D"ISO-8859-1" ?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> ------=_NextPart_000_011D_01C7E6E4.CCAD9B50-- As you can see the body of the email contains the email and its attachments Link to comment https://forums.phpfreaks.com/topic/66597-emailing-with-attachment/#findComment-333706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.