I am running php 4.3.2 on a Win 2000 server with IIS and cannot get the mail function to work with attachments. I receive the message but with no text in the body and an empty attachment. The same code works just fine on a Unix box. Anyone got any ideas?
The code is:
<?php
session_start();
error_reporting(E_ALL);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language=javascript>
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
$to = "me@mydomain.co.uk";
$from = "test@nowhere.com";
$subject = "Test email with attachment";
$message="";
$headers =
'From: <' . $from . '>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="XXXXboundary text"
This is a multipart message in MIME format.
--XXXXboundary text
Content-Type: text/plain
this is the body text
--XXXXboundary text
Content-Type: text/plain;
Content-Disposition: attachment;
filename="test.txt"
this is the attachment text
--XXXXboundary text--';
$success = mail($to, $subject, $message, $headers);
if ($success) {
echo "The email to $to from $from was successfully sent";
} else {
echo "An error occurred when sending the email to $to from $from";
}
?>
</body>
</html>