f



Mail from PHP

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();
	}

?>

0
jubileum (4)
8/7/2007 12:34:56 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
837 Views

Similar Articles

[PageSpeed] 34

>  Now it won't send any body text (The data filled in on the form)....

the call to mail() within the send method need to be changed to:

mail($this->to, $this->subject,  $this->body, $mime);


> ...and in an error condition it won't send any attachments either.

can you describe this a little better?

0
smsiebe (150)
8/7/2007 3:29:51 PM
On Aug 7, 5:29 pm, ELINTPimp <smsi...@gmail.com> wrote:
> >  Now it won't send any body text (The data filled in on the form)....
>
> the call to mail() within the send method need to be changed to:
>
> mail($this->to, $this->subject,  $this->body, $mime);
>
> > ...and in an error condition it won't send any attachments either.
>
> can you describe this a little better?

I Changed "" into $this->body, there is still no body text
I changed "" onto "test" there is still no body text

the error condition:
If I understand the source correct it makes a rmlog.xml file when the
number of arguments is not equal to 48. I receive these mails but also
without a body or attachment

0
jubileum (4)
8/9/2007 7:50:26 AM
Reply: