Just before leaving for a holiday my collegue modified this script.
Now it won't send any body text (The data filled in on the form) and
in an error condition it won't send any attachments either.
Because I don't understand PHP I cannot find the error. Who is willing
to help?
regards Ruud
Current PHP script:
<?php
$emailadres_rea cties = "st**********@m ysite.nl";
$emailadres_log bestanden = "st**********@m ysite.nl";
/*
* Class mime_mail
*/
class mime_mail
{
var $parts;
var $to;
var $from;
var $headers;
var $subject;
var $body;
/*
* void mime_mail()
* class constructor
*/
function mime_mail()
{
$this->parts = array();
$this->to = "";
$this->from = "";
$this->subject = "Test";
$this->body = "Body tekst";
$this->headers = "";
}
/*
* void add_attachment( string message, [string name], [string
ctype])
* Add an attachment to the mail object
*/
function add_attachment( $message, $name = "", $ctype =
"applicatio n/octet-stream")
{
$this->parts[] = array (
"ctype" =$ctype,
"message" =$message,
"encode" =$encode,
"name" =$name
);
}
/*
* void build_message(a rray part=
* Build message parts of an multipart mail
*/
function build_message($ part)
{
$message = $part[ "message"];
$message = chunk_split(bas e64_encode($mes sage));
$encoding = "base64";
return "Content-Type: ".$part[ "ctype"].
($part[ "name"]? "; name = \"".$part[ "name"]. "\"" : "").
"\nContent-Transfer-Encoding: $encoding\n\n$m essage\n";
}
/*
* void build_multipart ()
* Build a multipart mail
*/
function build_multipart ()
{
$boundary = "b".md5(uniqid( time()));
$multipart = "Content-Type: multipart/mixed; boundary = $boundary\n
\nThis is a MIME
encoded message.\n\n--$boundary";
for($i = sizeof($this->parts)-1; $i >= 0; $i--)
{
$multipart .= "\n".$this->build_message( $this->parts[$i]). "--
$boundary";
}
return $multipart.= "--\n";
}
/*
* void send()
* Send the mail (last class-function to be called)
*/
function send()
{
$mime = "";
if (!empty($this->from))
$mime .= "From: ".$this->from. "\n";
if (!empty($this->headers))
$mime .= $this->headers. "\n";
if (!empty($this->body))
$this->add_attachment ($this->body, "", "text/plain");
$mime .= "MIME-Version: 1.0\n".$this->build_multipar t();
mail($this->to, $this->subject, "", $mime);
}
}; // end of class
// begin sessie
session_start() ;
// tel aantal variabelen
$numElements = count($_POST);
if($numElements ==48)
{
$mail = new mime_mail();
$mail->from = "no*****@mysite .nl";
$mail->from = "st**********@m ysite.nl";
$mail->headers = "Errors-To: in**@mysite.nl";
$mail->to = $emailadres_rea cties;
$mail->subject = "aanmelding via sterktemeter";
$tmp = array_reverse($ _POST);
$tmp = array_slice($tm p,15);
$_POST = array_reverse($ tmp);
$_POST = array_reverse($ _POST);
$werknemer = array_slice($_P OST, 0, 8);
$werkgever = array_slice($_P OST, 8, 8);
$aanmelding = array_slice($_P OST, 16, 1);
$arbo = array_slice($_P OST, 17, 9);
$factuur = array_slice($_P OST, 26, 7);
$mail->body = $mail->body."\n\n".im plode("\n", $werknemer);
$mail->body = $mail->body."\n\n".im plode("\n", $werkgever);
$mail->body = $mail->body."\n\n".im plode("\n", $aanmelding);
$mail->body = $mail->body."\n\n".im plode("\n", $rabo);
$mail->body = $mail->body."\n\n".im plode("\n", $factuur);
$mail->send();
}
else
{
$mail = new mime_mail();
$mail->from = "st**********@m ysite.nl";
$mail->headers = "Errors-To: sp**@mysite.nl";
$mail->to = $emailadres_log bestanden;
$mail->subject = "logbestand sterktemeter";
$mail->body = "- logbestanden van de sterktemeter in bijgesloten XML
bestand -";
//verwerk ontvangen variabelen van Flash tot XML bestand
$data = $data."<UNIEKE_ ID>".$subject.S ession_ID()."</UNIEKE_ID>
\n";
$data = $data."<IP_ADRE S>".$REMOTE_ADD R."</IP_ADRES>\n";
$data = $data."<DATUM>" .date("d/m/Y")."</DATUM>\n";
$data = $data."<TIJD>". date("H:m")."</TIJD>\n";
$data = $data.implode(" \n", $_POST);
// maak een xml file met als bestandsnaam de sessie_id
$file = $subject.Sessio n_ID().".xml";
if (!$file_handle = fopen($file,"w" )) { echo "Cannot open
file"; }
if (!fwrite($file_ handle, $data)) { echo "Cannot write to
file"; }
// plaats attachment in variabele: $attachment
$attachment = fread(fopen($fi le, "r"), filesize($file) );
$mail->add_attachment ("$attachmen t", "rmlog.xml" , "txt/xml");
fclose($file_ha ndle);
// verwijder XML bestand van server
@unlink($file);
$mail->send();
}
?>