You are here: Mail from PHP « PHP Programming Language « IT news, forums, messages
Mail from PHP

Posted by Ruud on 08/07/07 12:34

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_reacties = "sterktemeter@mysite.nl";
$emailadres_logbestanden = "sterktemeter@mysite.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 =
"application/octet-stream")
{
$this->parts[] = array (
"ctype" => $ctype,
"message" => $message,
"encode" => $encode,
"name" => $name
);
}

/*
* void build_message(array part=
* Build message parts of an multipart mail
*/
function build_message($part)
{
$message = $part[ "message"];
$message = chunk_split(base64_encode($message));
$encoding = "base64";
return "Content-Type: ".$part[ "ctype"].
($part[ "name"]? "; name = \"".$part[ "name"]. "\"" : "").
"\nContent-Transfer-Encoding: $encoding\n\n$message\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_multipart();
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 = "noreply@mysite.nl";
$mail->from = "sterktemeter@mysite.nl";

$mail->headers = "Errors-To: info@mysite.nl";
$mail->to = $emailadres_reacties;

$mail->subject = "aanmelding via sterktemeter";
$tmp = array_reverse($_POST);
$tmp = array_slice($tmp,15);
$_POST = array_reverse($tmp);
$_POST = array_reverse($_POST);

$werknemer = array_slice($_POST, 0, 8);
$werkgever = array_slice($_POST, 8, 8);
$aanmelding = array_slice($_POST, 16, 1);
$arbo = array_slice($_POST, 17, 9);
$factuur = array_slice($_POST, 26, 7);

$mail->body = $mail->body."\n\n".implode("\n", $werknemer);
$mail->body = $mail->body."\n\n".implode("\n", $werkgever);
$mail->body = $mail->body."\n\n".implode("\n", $aanmelding);
$mail->body = $mail->body."\n\n".implode("\n", $rabo);
$mail->body = $mail->body."\n\n".implode("\n", $factuur);

$mail->send();

}
else
{
$mail = new mime_mail();
$mail->from = "sterktemeter@mysite.nl";
$mail->headers = "Errors-To: spam@mysite.nl";
$mail->to = $emailadres_logbestanden;
$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.Session_ID()."</UNIEKE_ID>
\n";
$data = $data."<IP_ADRES>".$REMOTE_ADDR."</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.Session_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($file, "r"), filesize($file));
$mail->add_attachment("$attachment", "rmlog.xml", "txt/xml");

fclose($file_handle);

// verwijder XML bestand van server
@unlink($file);

$mail->send();
}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация