php script works on external unix server, not on internal

Dear Sir or Madam

I’ve installed a xampp on my windows 7 pc. Initially I only worked directly on an external server. After having installed xampp on windows7 I’ve managed to make most scripts work. A problem occured however when trying to send mails with an attachment. The attachment gets entirely screwed up. Apparantly the file is damaged. Using the same script on the external server no problems occur. I’ve included the script.

Does anyone know where the problem lies and how I can put it right?

Tx

M

ps: the script
[php]<?php
// download fpdf class (http://fpdf.org)
require(‘fpdf.php’);
//require(‘c://xampp/php/PEAR/fpdf/fpdf.php’);

class AttachmentEmail {
private $from = ‘[email protected]’;
private $from_name = ‘Your Name’;
private $reply_to = ‘[email protected]’;
private $to = ‘’;
private $subject = ‘’;
private $message = ‘’;
private $attachment = ‘’;
private $attachment_filename = ‘’;

public function __construct($to, $subject, $message, $attachment = ‘’, $attachment_filename = ‘’) {
$this -> to = $to;
$this -> subject = $subject;
$this -> message = $message;
$this -> attachment = $attachment;
$this -> attachment_filename = $attachment_filename;
}

public function mail() {
if (!empty($this -> attachment)) {
$filename = empty($this -> attachment_filename) ? basename($this -> attachment) : $this -> attachment_filename ;
$path = dirname($this -> attachment);
$mailto = $this -> to;
$from_mail = $this -> from;
$from_name = $this -> from_name;
$replyto = $this -> reply_to;
$subject = $this -> subject;
$message = $this -> message;

$file = $path.’/’.$filename;
$file_size = filesize($file);
$handle = fopen($file, “r”);
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = “From: “.$from_name.” <”.$from_mail.">\r\n";
$header .= “Reply-To: “.$replyto.”\r\n”;
$header .= “MIME-Version: 1.0\r\n”;
$header .= “Content-Type: multipart/mixed; boundary=”".$uid.""\r\n\r\n";
$header .= “This is a multi-part message in MIME format.\r\n”;
$header .= “–”.$uid."\r\n";
$header .= “Content-type:text/plain; charset=iso-8859-1\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n\r\n”;
$header .= $message."\r\n\r\n";
$header .= “–”.$uid."\r\n";
$header .= “Content-Type: application/octet-stream; name=”".$filename.""\r\n"; // use diff. tyoes here
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment; filename=”".$filename.""\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= “–”.$uid."–";

if (mail($mailto, $subject, “”, $header)) {
return true;
} else {
return false;
}
} else {
$header = “From: “.($this -> from_name).” <”.($this -> from).">\r\n";
$header .= “Reply-To: “.($this -> reply_to).”\r\n”;

if (mail($this -> to, $this -> subject, $this -> message, $header)) {
return true;
} else {
return false;
}

}
}
}

$sendit = new AttachmentEmail(‘[email protected]’, ‘Merry Christmas!’, ‘Hi’, ‘svbp.jpg’);
$sendit -> mail();
?>[/php]

as I can see windows pc’s dont have any mailtransport smtp servers installed by default, so here you need to define eg your isp’s smtp server, i guess in php.ini…

quick google got me this

oh cant post links… well ill post content then :

PHP makes it easy to send mail from Web applications. But it still needs a bit of configuration. As you probably know, PHP configuration happens php.ini.

The relevant section for email configuration is [mail function], and to make PHP use an external mail server you must set SMTP to your ISP’s mail server’s address. This will be the same address that you use in your email program for the outgoing mail server, “smtp.isp.net”, for example. The other setting sendmial_from, which specifies the default email address PHP emails are sent from.

Configure PHP to Use a Remote SMTP Server for Sending Mail

Note that setting up the internal mail function to use SMTP is only available on Windows. On other platforms, PHP should use the locally available sendmail or sendmail drop-in just fine. Alternatively, you can use the PEAR Mail Package.

A typical configuration might look like:

[mail function]
SMTP = smtp.isp.net
sendmail_from = [email protected]

By Heinz Tschabitscher, About.com Guide

Sponsor our Newsletter | Privacy Policy | Terms of Service