473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 = "st**********@mysite.nl";
$emailadres_logbestanden = "st**********@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 = "no*****@mysite.nl";
$mail->from = "st**********@mysite.nl";

$mail->headers = "Errors-To: in**@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 = "st**********@mysite.nl";
$mail->headers = "Errors-To: sp**@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();
}

?>

Aug 7 '07 #1
2 2652
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?

Aug 7 '07 #2
On Aug 7, 5:29 pm, ELINTPimp <smsi...@gmail.comwrote:
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

Aug 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Merijn Boom | last post by:
Hi there, I'm trying to create an html mail with embedded pictures in it. I run perl on Windows and Red Hat but I cannot get your module (Mail::Sender) to work. I'm just trying to run the...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
3
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
4
by: J Huntley Palmer | last post by:
How may I setup a proper HTML mail message with embedded href links using PHP, that follows all the MIME rules? Any examples or links would be appreciated. Thanks!
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
6
by: cover | last post by:
I'm using PHP 5 at home w/Apache & MySQL on a test system where I write through a form to a database and also send an email to people on a drop down list. Purpose for this is an electronic log at...
2
mikek12004
by: mikek12004 | last post by:
Before posting here I google it and saw ablut 30 pages for a solution so I pretty much excluded the obvious things. The code is <?php //now to send the mails to seller...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.