Jump to content

Recommended Posts

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 = 'test@test.nl';
$subject = "test mail";   

$random_hash = md5(date('r', time())); 
$headers = "From: test@test.nl\r\nReply-To: test@test.nl"; 
$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:test@test.nl</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

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 = 'test@test.nl';
$subject = "test mail";   

$random_hash = md5(date('r', time())); 
$headers = "From: test@test.nl\r\nReply-To: test@test.nl"; 
$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:test@test.nl</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

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: <d.roberts@digimomedia.nl>
Delivered-To: 2-d.roberts@digimomedia.nl
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 <d.roberts@digimomedia.nl>; Sat, 25 Aug 2007 06:54:34 +0200 (CEST)
Message-ID: <012001c7e6d4$09332330$6501a8c0@DESIGNER>
Reply-To: "Dwayne Roberts" <d.roberts@adquick.nl>
From: "Dwayne Roberts" <d.roberts@digimomedia.nl>
To: <d.roberts@digimomedia.nl>
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" <d.roberts@digimomedia.nl>
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

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.