PDA

View Full Version : mail form with upload file



chechu
06-07-2008, 04:30 PM
Hey all,
I have this mail form, with this as php code:

<?php
if ($_POST["action"] == "send"){
if ($_POST[naam] != " je naam" and $_POST[naam] != "" and $_POST[email] != " je e-mail adres" and $_POST[email] != "" and $_POST[bericht] != "") {
mail ("info@site.com", "via site",
"
Naam: ".$_POST['naam']."
E-mail: ".$_POST['email']."
Bericht: ".$_POST['bericht']."
",
"From: ".$_POST['naam']." <".$_POST['email'].">");
$subject = "je bericht aan Ceci Casariego";
$msg = "
Dit is een automatisch verzonden mail. Gelieve niet te antwoorden.
Beste $_POST[naam],
Bedankt voor je bericht aan Ceci.
Ze zal je zo snel mogelijk beantwoorden
Dit was je bericht:
$_POST[bericht]
";
mail($_POST[email], $subject, $msg);
echo 'Bedankt.<br><br>Je bericht is verzonden, <br>en je zult een bevestiging ontvangen. <br><br>&nbsp;<br><br>';
}
else{
echo 'Gelieve alle velden in te vullen<br><br>Je naam, email adres en bericht<br> zijn verplichte velden.<br><br><a href="contactNL.html"><font color="#565656;">[graag opnieuw]</font></a><br><br>&nbsp;<br>';
}
}
?>

I wish to add an upload function (attachment), like this:

<script type="text/JavaScript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>
<form name="form1" method="post" action="contactNL.php">
<input type="hidden" name="action" value="send">
<input type="text" name="naam" value=" je naam" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
<br>
<input type="text" name="email" value=" je email adres" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
<br>
<input type="file" name="fieldname" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;"><br>
<textarea name="bericht" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:70px" onfocus="clearDefault(this)"> je bericht</textarea>
<br>
&nbsp;&nbsp;&nbsp; <input type="image" src="images/sendarrow.gif" value="send">
&nbsp;&nbsp;&nbsp; <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer">
</form>
But when I send the mail, the attached file isn't sent. What needs to be changed in the php ?
The attachment is not oligatory; the other fields need to be filled in.

chechu
06-11-2008, 07:11 AM
Anyone, please ?

chechu
06-13-2008, 09:14 AM
I might be a code monkey, but it seems none hears me roar !

rangana
06-13-2008, 09:16 AM
Yes, we are, and I'm hearing the roar :D

Have you had tried gone through PHP Manual - Handling File Uploads (http://us3.php.net/features.file-upload)

chechu
06-13-2008, 09:31 AM
Excellent ears !
I will explain you my problem: I am an artist, complexe personality, living in another world, so php and all its ' ; $ array ' < and these signs are trees into the huge forrest of webdesign to me. Html I can work with a bit, but no php, as that involves more logical thinking. So what I am trying to say is that I usually pay people that I admire doing things I cannot do (like the plumber). Webdesigners ask so much money for their work, that I now refuse to pay for it. Dynamic Drive actually built and rebuilt my site, and all the people on this platform can count on my greatest appreciation.
To get to the point: I do not understand what is explained in your link. I honestly don't. Does that mean I want to get the scripts just like that, no questions asked ? Would be perfect to work with, but I'd rather see how it is created, from the very start. Unfortunately that cannot be done; therefore I'd need a private teacher. Or as John Scheuer ones told me on this forum: "teach a man how to fish, and he'll get drunk in the harbour all day." Or something like that ...
This forum actually helped me in creating a new project about interaction of unknown people, the social help, not being selfish. I'm working on it, first project after two years of inactivity (due to motherhood), so check out the site you've built !

If I add this in the html, should it work then ?


<script type="text/JavaScript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>
<form name="form1" method="post" enctype="multipart/form-data" action="contactNL.php">
<input type="hidden" name="action" value="send">
<input type="text" name="naam" value=" je naam" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
<br>
<input type="text" name="email" value=" je email adres" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
<br>
<input type="file" name="fieldname" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;"><br>
<textarea name="bericht" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:70px" onfocus="clearDefault(this)"> je bericht</textarea>
<br>
&nbsp;&nbsp;&nbsp; <input type="image" src="images/sendarrow.gif" value="send">
&nbsp;&nbsp;&nbsp; <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer">
</form>

rangana
06-13-2008, 09:58 AM
I'm actually trying to give you a link since I'm not on my wits with regards to PHP.
But since its a boring afternoon, and got nothing to do, I worked with the code. And here's what I've got:



<?php
if ($_POST["action"] == "send"){
$uploaddir = 'c:\\progra~1\\xampp\\htdocs\\'; # This will be your web directory.
$uploadfile = $uploaddir.basename($_FILES['fieldname']['name']);
if (move_uploaded_file($_FILES['fieldname']['tmp_name'],$uploadfile)) {
echo "File is valid, and was successfully uploaded.<br>\n<img src='".basename($_FILES['fieldname']['name'])."'> <br>\n";
} else {
echo "Possible file upload attack!\n";
}



if ($_POST[naam] != " je naam" and $_POST[naam] != "" and $_POST[email] != " je e-mail adres" and $_POST[email] != "" and $_POST[bericht] != "") {
mail ("info@site.com", "via site",
"
Naam: ".$_POST['naam']."
E-mail: ".$_POST['email']."
Bericht: ".$_POST['bericht']."
",
"From: ".$_POST['naam']." <".$_POST['email'].">");
$subject = "je bericht aan Ceci Casariego";
$msg = "
Dit is een automatisch verzonden mail. Gelieve niet te antwoorden.
Beste $_POST[naam],
Bedankt voor je bericht aan Ceci.
Ze zal je zo snel mogelijk beantwoorden
Dit was je bericht:
$_POST[bericht]
";
mail($_POST[email], $subject, $msg);
echo 'Bedankt.<br><br>Je bericht is verzonden, <br>en je zult een bevestiging ontvangen. <br><br>&nbsp;<br><br>';
}
else{
echo 'Gelieve alle velden in te vullen<br><br>Je naam, email adres en bericht<br> zijn verplichte velden.<br><br><a href="contactNL.html"><font color="#565656;">[graag opnieuw]</font></a><br><br>&nbsp;<br>';
}
}
?>


...and have this in your form tag:


enctype="multipart/form-data"


I'm having XAMPP, and it's working, just edit the value of $uploaddir.

See if it helps.

chechu
06-13-2008, 10:14 AM
It looked like I'd have a boring day also, but that has changed.
I'll have a look at it !

What does this mean ?

I'm having XAMPP, and it's working, just edit the value of $uploaddir.
Is the upload directory where the file will be placed on my computer when sent ?
I just want the file as an attachment in the email, nothing more.
Also, if someone wants to send me like five pictures, how can they be uploaded ?

Just tried the form, and the message is sent, but no email.
Check here: http://www.cecicasariego.com/testcontact.html
Also, when there is no file uploaded, there should not come up the message: 'possible file attack'.

calumogg
06-16-2008, 09:37 AM
I am no great PHP coder, but I had a quick look on google and found this tutorial (http://www.sitepoint.com/article/advanced-email-php/5) this explains how to send a email with attachments I have also attached the zip file containing the sample PHP and HTLM files.

Hope the helps

chechu
06-16-2008, 10:40 AM
<?php
// Read POST request params into global vars
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

$headers = "From: $from";

if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}

// Send the message
$ok = @mail ($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
Where do I put the mail adress where it needs to be sent to ?
I changed @mail into an existing adress, but the form didn't work then.
You can check it here (http://www.cecicasariego.com/testcontact.html)

boogyman
06-16-2008, 01:22 PM
$ok = @mail ($to, $subject, $message, $headers);

take out the space


$ok = @mail($to, $subject, $message, $headers);

calumogg
06-16-2008, 01:43 PM
To change where it who it goes to change:


<?php
// Read POST request params into global vars
$to = $_POST['to'];

To something like:


<?php
// Read POST request params into global vars
$to = 'me@mydomain.com';


You can the also remove the 'To' input on the form

Hope that helps :)

chechu
06-16-2008, 05:47 PM
This is what I have in html:

<script type="text/JavaScript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>

<form action="testcontact.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="send">
<input type="text" name="from" value=" your name" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
<br>
<input type="text" name="email" value=" your email adress" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
<br>
<input type="file" name="fileatt" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
<br>
<textarea name="message" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:63px"> message</textarea>
<br>
&nbsp;&nbsp;&nbsp; <input type="image" src="images/sendarrow.gif" value="send">
&nbsp;&nbsp;&nbsp; <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer">
</form>

And this is the php:

<?php
// Read POST request params into global vars
$to = 'info@mysite.com';
$from = $_POST['from'];
$email = $_POST['email'];
$message = $_POST['message'];

// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

$headers = "From: $from";

if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}

// Send the message
$ok = @mail($from, $email, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>

Then mail never gets sent. In orange you can see the adjustments I made; obviously wrong. What is wrong ?
See it here in action: http://www.cecicasariego.com/testcontact.html

calumogg
06-16-2008, 06:11 PM
Hmm ok try this (I havent tested this):


<?php
// Read POST request params into global vars
$to = 'info@mysite.com';
$from = $_POST['from'];
$email = $_POST['email'];
$message = $_POST['message'];

// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

$headers = "From: $email ";

if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}

// Send the message
$ok = @mail($to, 'SUBJECT', $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>


<script type="text/JavaScript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
</script>

<form action="testcontact.php" method="POST" enctype="multipart/form-data">
<p>
<input type="hidden" name="action" value="send">
</p>
<p>
<input type="text" name="from" id="from" value="your name" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted #cc6600; border-right:0px; border-bottom: 1px dotted #cc6600; width:150px">
<br>
<input type="text" name="email" id="email" value=" your email adress" onfocus="clearDefault(this)" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
<br>
<input type="file" name="fileatt" id="fileatt" style="border-top:0px; border-left: 1px dotted purple; border-right:0px; border-bottom: 1px dotted purple; width:150px;">
<br>
<textarea name="message" id="message" style="border-top:0px; border-left:1px dotted #0066cc; border-right:0px; border-bottom: 1px dotted #0066cc; width:150px; height:63px"> message</textarea>
<br>
&nbsp;&nbsp;&nbsp;
<input type="image" src="images/sendarrow.gif" value="send">
&nbsp;&nbsp;&nbsp; <img src="images/clear.gif" onclick="document.getElementById('form1').reset();" style="cursor:pointer">
</p>
</form>

chechu
06-16-2008, 06:27 PM
It works, but with the following remarks:
- the email and name and subject areas need to be filled in; now the mail gets sent without anything filled in.
- I know the email adress of the sender, but not his name (although requested)
- their is no confirmation mail sent

Is it possible to have the above php, mixed with the follwing one:

<?php

if ($_POST["action"] == "send"){

if ($_POST[name] != " your name" and $_POST[name] != "" and $_POST[email] != " your e-mail adress" and $_POST[email] != "" and $_POST[message] != "") {
mail ("info@site.com", "via website (EN)",
"
Name: ".$_POST['name']."
E-mail: ".$_POST['email']."
Message: ".$_POST['message']."

",
"From: ".$_POST['name']." <".$_POST['email'].">");

$subject = "your message to Ceci Casariego";

$msg = "

This is an automatically sent email. Please do not reply.

Dear $_POST[name],

Thanks for your message to Ceci.
She will get back to you as soon as possible.

This was your message:
$_POST[message]
";

mail($_POST[email], $subject, $msg);

echo 'Thanks ! <br>Your message has been sent,<br> and you will receive a confirmation mail. <br><br> We will get back to you as soon as we can.<br>&nbsp;<br><br>';

}

else{
echo 'Please fill in all data !<br><br>Your name, email adress and message <br>are mandatory fields.<br><br><a href="contact.html"><font color="#565656;">[again please]</font></a><br>&nbsp;<br>';
}
}
?>

And how can I send more than one attachment in the same email ?

chechu
06-18-2008, 06:46 PM
It is starting to become a real puzzle, therefore I'd like to put everything together, so that hopefully an expert can make it work:
This is what I need the form to do:

- fields: name, email, upload image, message
- name, email and message are obligatory fields
- possibility to upload attachments (mainly images)
- when one image is uploaded, link appears under it, asking to add another image, or delete the previous
- possibility to send max. 10 attachments per email
- when sent, a confirmation appears
- if error in the fields, not being sent to another page saying there's an error, but remaining at the same page, where the errors are put in the html-form (showing f.ex. with an asterisk or image what is missing)
- the confirmation shows if there was an attachment or no (f.ex. message (without attachment, with 5, 8 attachments) sent)
- a confirmation email is sent to the poster

Can anyone put this all together in one php form, please ??
I know it is a lot to ask, but I also know we have real experts in this forum !

chechu
06-22-2008, 02:39 PM
Anyone, please ?

chechu
06-27-2008, 01:54 PM
Is it also posible, besides the above, to add a 'send me a copy' option ?

jrizzo
06-27-2008, 09:27 PM
I'm a PHP newb who is trying to learn more about coding. In the past, I've used a utility called FormsToGo. It can generate the PHP code (ASP and Perl too) and provides lots of options for recipients, conformation emails, attachments, security and more. It may be easier to let FTG generate your code instead of killing yourself trying to figure out how to make your own code work. You could then examine the code FTG generates to see how it's done. I believe the publisher offers a 30 free trial.

Here is a link to the product's features page:

http://www.bebosoft.com/products/formstogo/features.php

Hope this is helpful.

chechu
07-01-2008, 08:17 AM
I tried the package you suggested, but I cannot find the requiered features in it.
I' d really have to stick to the needs described above, as I cannot play around with it.
Can anyone help me with this, please ?

chechu
07-05-2008, 08:40 AM
I am getting closer ! I adapted a script, and this is the result: http://www.cecicasariego.com/testcontact2.php, but there is an error, and I still need the following features:

- possibility to upload attachments (mainly images)
- when one image is uploaded, link appears under it, asking to add another image, or delete the previous
- possibility to send max. 10 attachments per email
- the confirmation shows if there was an attachment or no (f.ex. message (without attachment, with 5, 8 attachments) sent)

Can anyone have a look what causes the error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /customers/cecicasariego.com/cecicasariego.com/httpd.www/testcontact2.php:8) in /customers/cecicasariego.com/cecicasariego.com/httpd.www/testcontact2.php on line 145

and how to add the other functions, please. The current code (without the captcha) is in the next reply.

chechu
07-05-2008, 08:53 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>

<title>Ceci Casariego: contact gegevens</title>
<meta name="Author" content="Fine arts, portraits and decoration by Ceci Casariego Mazereel">
<meta name="DESCRIPTION" content="Ceci Casariego: portretten, ontwerp, design en interieur decoratie">
<meta name="KEYWORDS" content="cecicasariego,casariegoart,Cecilia,Ceci,Chechu,Laura,Casariego,Mazereel,Bruno,Negrito,Argentina,Argentinie,schilderes,paintor,artist,artiste,pintora,kunstenares ,portretkunst,portret,portrait,portretkunstenaar,portretkunstenares,directory,paintings,pinturas,kunst,art,arte,oil,oleo,olie,canvas,doek,tela,paper,papel,papie r,ink,tinta,inkt,pastel,acrilico,acrilic,acriel,decoratie,decoration,decoracion,fresco,wallpainting,wood,board,muurschilderijen,interieur,interior,verfeffecten, trompe,loeil,portretten,portraits,retratos,realistic,realistisch,real,fotografisch,photographic,Belgium,Belgica,Belgie,Cambrinus,Damier,hotel,Plenso,Belstat,Out side,Travel,Bert,Lamaire,Unitron,Kwakkelnest,Neerplaats,Deltronic,Nocturnes,Piet,Lesage,Videoland,Poperinge,DHaene,Azart,Kaders,Bonnaffe,Alinia,Nudes,Flemish,Be gijnhof,Diest,ExLibris,kunstacademie,kunstakademie,Euro,Region,Euroregion,Miss,verkiezing,election,naaktschilderijen,kunstschilder,portretkunst">
<meta name="ROBOTS" content="NOARCHIVE">
<meta name="REVISIT-AFTER" content="2 days">
<meta name="Classification" content="Artist,decorator,portraitist">
<meta name="language" content="English,Nederlands,Français">
<meta name="doc-type" content="Public">
<meta name="doc-class" content="Completed">
<meta name="doc-rights" content="Copy Written Work">
<meta name="resource-type" content="document">
<meta name="generator" content="Developed by Bruno Mazereel">
<meta name="distribution" content="Global">
<meta name="rating" content="General">
<meta name="copyright" content="Ceci and Bruno Casariego-Mazereel">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" media="all" type="text/css" href="site.css">
<meta http-equiv="imagetoolbar" content="no">
<script src="links.js" type="text/javascript"></script>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">

<style type="text/css">
<!--
div#container {
margin:0 auto;
background: #f2f4f7;
}

label {
float: left;
width: 140px;
text-align: left;
padding-top: 5px;
}

input, textarea {
padding: 3px;
margin: 3px;
border: 1px solid #bac5d6;
font: 10px Verdana, sans-serif;
background: #fff;
}
input.fout, textarea.fout {
border: 1px solid #FF0000;
}

label.fout {
color: #FF0000;
}
-->
</style>

</head>

<body>


<div id="content">
<?php
if(isset($errors)) {
echo $errors;
}
?>

<script type="text/javascript">
<!--
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// -->
</script>

<div id="header-main">
<div id="headerNL">

<h1>Ceci CASARIEGO</h1>
<ul>
<li class="nav"><a href="index.html">home</a></li>
<li class="nav"><a href="portfolioNL.html">portfolio</a></li>
<li class="nav"><a href="cvNL.html">curriculum</a></li>
<li class="nav"><a href="newsNL.html">nieuws</a></li>
<li class="nav"><a href="linksNL.html">links</a></li>
<li class="nav"><a href="testNL.html">getuigenissen</a></li>
<li class="hover">contact</li>
</ul>

</div>
</div>

<div id="body-main">
<div id="body">

<div id="left">
<div style="padding-top:15px; padding-bottom:17px;"><input type="text" value=" True Artist LinkedIn Group" style="width:135px; border:1px solid #bbaaaa">
<br>
<a href="http://artists.cecicasariego.com" target="_blank"><img src="images/meer.gif" style="border:0px; padding-top:5px;"></a></div>
<ul class="sub-link">
<li><a href="copyNL.html">© copyright 2004-2008</a></li>
<li class="noimg"><a href="contact.html">| EN |</a></li>
</ul>

<div id="event">
<br>&nbsp;<br>
<img src="images/sendarrow.gif">&nbsp; portret aanvragen: <a href="faqNL.html">veelgestelde vragen</a><br>
<img src="images/sendarrow.gif">&nbsp; voor meer informatie: +32.(0)475.98.49.96
</div>

</div>

<div id="right">
<h2>Contact</h2>
<p class="top-text">

Heb je vragen of opmerkingen, laat het Ceci weten. Heb je vragen over wat belangrijk is bij een portretopdracht,
bekijk dan eerst de <a href="faqNL.html">veelgestelde vragen</a>. Je kan tot vijf foto's toevoegen.
<br>&nbsp;<br>&nbsp;<br>


<?php
############################################
# Filename : contact.php #
#------------------------------------------#
# Written By : Thijs Ferket #
# Website : www.ferket.net #
#------------------------------------------#
############################################

ini_set('display_errors', 1);
error_reporting(E_ALL);

ob_start();
session_start();

// Config Gedeelte
$cfg['url'] = "http://www.cecicasariego.com";// Site waarnaar je terug gaat als je een bericht hebt achtergelaten
$cfg['naam'] = "Ceci Casariego"; // Webmaster naam
$cfg['email'] = "info@cecicasariego.com"; // Webmaster E-mail
$cfg['spam'] = 10; // Anti Spam Tijd in Minuten ( Voer "0" om de Spam Beveiliging uit te zetten )
$cfg['text'] = TRUE; // Bij Fout Text Rood maken ( TRUE voor aan, FALSE voor uit )
$cfg['input'] = TRUE; // Bij Fout Border om Vakje Rood maken ( TRUE voor aan, FALSE voor uit )
$cfg['HTML'] = TRUE; // Een HTML email ( TRUE voor aan, FALSE voor uit )
$cfg['CAPTCHA'] = TRUE; // CAPTCHA ( TRUE voor aan, FALSE voor uit )


// Hieronder niks meer veranderen
// E-mail Checker / Validator
function checkmail($email)
{
if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email))
{
return TRUE;
}
return FALSE;
}

$formulier = TRUE;

if(!isset($_COOKIE['formulier']))
{
if(isset($_POST['wis']) && ($_SERVER['REQUEST_METHOD'] == "POST"))
{
foreach($_POST as $key => $value)
{
unset($value);
}
header("Location: ".$_SERVER['PHP_SELF']."");
}

if(isset($_POST['verzenden']) && ($_SERVER['REQUEST_METHOD'] == "POST"))
{
$aFout = array();

$naam = trim($_POST['naam']);
$email = trim($_POST['email']);
$onderwerp = trim($_POST['onderwerp']);
$bericht = trim($_POST['bericht']);

if($cfg['CAPTCHA'])
{
$code = $_POST['code'];
}

if(empty($naam) || (strlen($naam) < 3) || eregi("[<>]", $naam) )
{
$aFout[] = "Er is geen naam ingevuld.";
unset($naam);
$fout['text']['naam'] = TRUE;
$fout['input']['naam'] = TRUE;
}
if(empty($email))
{
$aFout[] = "Er is geen e-mail adres ingevuld.";
unset($email);
$fout['text']['email'] = TRUE;
$fout['input']['email'] = TRUE;
}
elseif(checkmail($email) == 0)
// Wanneer je PHP 5.2 > gebruikt
//elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$aFout[] = "Er is geen correct e-mail adres ingevuld.";
unset($email);
$fout['text']['email'] = TRUE;
$fout['input']['email'] = TRUE;
}
if(empty($onderwerp))
{
$aFout[] = "Er is geen onderwerp ingevuld.";
unset($onderwerp);
$fout['text']['onderwerp'] = TRUE;
$fout['input']['onderwerp'] = TRUE;
}
if(empty($bericht))
{
$aFout[] = "Er is geen bericht ingevuld.";
unset($bericht);
$fout['text']['bericht'] = TRUE;
$fout['input']['bericht'] = TRUE;
}
if($cfg['CAPTCHA'])
{
if(strtoupper($code) != $_SESSION['captcha_code'])
{
$aFout[] = "Er is geen correcte code ingevuld.";
$fout['text']['code'] = TRUE;
$fout['input']['code'] = TRUE;
}
}
if(!$cfg['text'])
{
unset($fout['text']);
}
if(!$cfg['input'])
{
unset($fout['input']);
}
if(!empty( $aFout ))
{
$errors = '
<div id="errors">
<ul>';
foreach($aFout as $sFout)
{
$errors .= " <li>".$sFout."</li>\n";
}
$errors .= "</ul>
</div>";
}
else
{
$formulier = FALSE;


if($cfg['HTML'])
{
// Headers
$headers = "From: \"Contact Formulier\" <".$cfg['email'].">\r\n";
$headers .= "Reply-To: \"".$naam."\" <".$email.">\n";
$headers .= "Return-Path: Mail-Error <".$cfg['email'].">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";


$bericht = '

chechu
07-05-2008, 08:54 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>

<body>
<br />
<b>Naam:</b> '.$naam.'<br />
<b>Email:</b> <a href=\"mailto:'.$email.'\">'.$email.'</a><br />
<br />
<b>Bericht:</b><br />
'.$bericht.'
<br />
<br />
<br />
--------------------------------------------------------------------------<br />
<b>Datum:</b> '.date("d-m-Y @ H:i:s").'<br />
<b>IP:</b> <a href=\"http://sunny.nic.com/cgi-bin/whois?domain='.$_SERVER['REMOTE_ADDR'].'\">'.$_SERVER['REMOTE_ADDR'].'</a><br />
<b>Host:</b> '.gethostbyaddr($_SERVER['REMOTE_ADDR']).'<br />
</body>
</html>';
}
else
{
$bericht_wrap = wordwrap ($bericht, 40, "\n", 1);
// Headers
$headers = "From: \"Contact Formulier\" <".$cfg['email'].">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset='iso-8859-1'\n";

// Bericht
$message = "Naam: ".$naam." \n";
$message .= "E-mail: ".$email." \n";
$message .= "Bericht:\n".$bericht_wrap." \n ";
$message .= " \n ";
$message .= "Datum: ".date("d-m-Y H:i:s")." \n";
$message .= "------------------------------------------------------- \n ";
$message .= "IP: ".$_SERVER['REMOTE_ADDR']." \n ";
$message .= "Host: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])." \n ";

}

if(mail($cfg['email'], "[Contact] ".$onderwerp, $bericht, $headers))
{
if(isset($_POST['stuurkopie']))
{
$headers = "From: \"Contact Formulier\" <".$email.">\r\n";
$headers .= "Reply-To: \"".$naam."\" <".$email.">\n";
$headers .= "Return-Path: Mail-Error <".$email.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";

mail($email, "[Contact] ".$onderwerp, $bericht, $headers);

}

unset($naam, $email, $onderwerp, $bericht);
setcookie("formulier", 1, time() + ( $cfg['spam'] * 60 ) );

echo "
<p>
Uw bericht is succesvol verzonden, er word zo snel mogelijk gereageerd.<br />
<br />
Met vriendelijke groeten,<br />
<b>".$cfg['naam']."</b>
</p>
";
}
else
{
echo "Er is een fout opgetreden bij het verzenden van de email";
}
header("refresh:3;url=".$cfg['url']."");
}
}
if($formulier)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="style.css" rel="stylesheet" type="text/css" />

<title>Contact Formulier door Thijs</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="nl" />
</head>

<body>
<div id="container">
<?php
if(isset($errors)) {
echo $errors;
}
?>


<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<p>
<label <?php if(isset($fout['text']['naam'])) { echo 'class="fout"'; } ?>>Naam:</label>
<input type="text" id="naam" name="naam" maxlength="30" <?php if(isset($fout['input']['naam'])) { echo 'class="fout"'; } ?> value="<?php if (!empty($naam)) { echo stripslashes($naam); } ?>" /><br />

<label <?php if(isset($fout['text']['email'])) { echo 'class="fout"'; } ?>>Email:</label>
<input type="text" id="email" name="email" maxlength="255" <?php if(isset($fout['input']['email'])) { echo 'class="fout"'; } ?> value="<?php if (!empty($email)) { echo stripslashes($email); } ?>" /><br />

<label <?php if(isset($fout['text']['onderwerp'])) { echo 'class="fout"'; } ?>>Onderwerp:</label>
<input type="text" id="onderwerp" name="onderwerp" maxlength="40" <?php if(isset($fout['input']['onderwerp'])) { echo 'class="fout'; } ?> value="<?php if (!empty($onderwerp)) { echo stripslashes($onderwerp); } ?>" /><br />

<label <?php if(isset($fout['text']['bericht'])) { echo 'class="fout"'; } ?>>Bericht:</label>
<textarea id="bericht" name="bericht" <?php if(isset($fout['input']['bericht'])) { echo 'class="fout"'; } ?> cols="30" rows="6"><?php if (!empty($bericht)) { echo stripslashes($bericht); } ?></textarea><br />

<?php
if($cfg['CAPTCHA'])
{
?>
<label></label>
<img src="captcha.php" alt="" /><br />

<label <?php if(isset($fout['text']['code'])) { echo 'class="fout"'; } ?>>Code:</label>
<input type="text" id="code" name="code" maxlength="4" size="4" <?php if(isset($fout['input']['code'])) { echo 'class="captcha fout"'; } ?> /><br />
<?php
}
?>
<label for="stuurkopie">Stuur mij een kopie</label><input type="checkbox" id="stuurkopie" name="stuurkopie" value="1" /><br />

<label></label>
<input type="submit" id="verzenden" name="verzenden" value="verzenden" />
<input type="submit" id="wis" name="wis" value="Wis velden" />
</p>
</form>

</div>
</div>
</div>

</body>
</html>

<?php
}
}
else
{
echo "
<p>
U kunt maar eens in de ".$cfg['spam']." minuten een e-mail versturen!<br />
U wordt nu automatisch doorgestuurd.
</p>";
header("refresh:3;url=".$cfg['url']."");
}
?>

chechu
07-08-2008, 08:08 AM
Okay, now it is getting way too compicated, so let's start again.

I have two codes, of which one gives me an error.

This is the link where you can see the code at work:http://www.cecicasariego.com/testcontact2.php

This is the error message:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /customers/cecicasariego.com/cecicasariego.com/httpd.www/testcontact2.php:8) in /customers/cecicasariego.com/cecicasariego.com/httpd.www/testcontact2.php on line 145


You can find the code of the script in the two post before this one. What causes the error ?

Then my next step would be to mix that script with the one below, and then I have reached my goal. So bear with me just this one more, and then I have the perfect script !

chechu
07-08-2008, 08:15 AM
multiple upload form

<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL);
$title = 'Dynamic Multiple File Uploads';
$msgs = array ();
$errs = array ();
/*
Constanten voor exif_imagetype ()
1 IMAGETYPE_GIF
2 IMAGETYPE_JPEG
3 IMAGETYPE_PNG
*/
$allowed = array (IMAGETYPE_JPEG);

function resize ($path, $dst_w) {
list ($src_w, $src_h) = getimagesize ($path);
if ($dst_w < $src_w) {
$ratio = $dst_w / $src_w;
$dst_h = ceil ($ratio * $src_h);
$src = imagecreatefromjpeg ($path);
$dst = imagecreatetruecolor ($dst_w, $dst_h);
imagecopyresampled ($dst, $src, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
imagejpeg ($dst, $path, 80);
imagedestroy ($src);
imagedestroy ($dst);
}
}

// business logic
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n = count ($_FILES['userfile']['error']);
for ($i = 0; $i < $n; $i++) {
if (!$_FILES['userfile']['error'][$i]) {
$tmp = $_FILES['userfile']['tmp_name'][$i];
$name = $_FILES['userfile']['name'][$i];
$dir = 'images/';
if (!in_array (exif_imagetype ($tmp), $allowed)) {
array_push ($errs, 'Sorry, alleen JPG');
}
elseif ($_FILES['userfile']['size'][$i] > 50000) {
array_push ($errs, 'Sorry, 50 KB max');
}
elseif (file_exists ($dir . $name)) {
array_push ($errs, $name . ' bestaat al!');
}
else {
$path = $_SERVER['DOCUMENT_ROOT'] . '/' . $dir . $name;
if (is_uploaded_file ($tmp)) {
if (move_uploaded_file ($tmp, $path)) {
chmod ($path, 0644);
resize ($path, 568);
array_push ($msgs, 'Geupload: ' . $name);
array_push ($msgs, '<img style="border: 1px solid #000; " src="' . $dir . $name . '">');
}
}
}
}
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jan Koehoorn | <?php echo $title; ?></title>

<link rel="stylesheet" type="text/css" media="screen" href="reset.css" />
<link rel="stylesheet" type="text/css" media="screen" href="oop.css" />
<style type="text/css">
form {padding: 10px;}
ul.msgs {margin: 10px; padding: 10px; border: 2px solid #00f; background: #99f;}
ul.errs {margin: 10px; padding: 10px; border: 2px solid #f00; background: #f99;}
ul.msgs li,
ul.errs li {color: #000;}
</style>

<script type="text/javascript" src="mootools/mootools.js"></script>
<script type="text/javascript">
window.addEvent ('domready', function () {
$$('a.add').each (function (item) {
item.addEvent ('click', function (e) {
e = new Event (e).preventDefault ();
var p = item.getParent ();
var clone = p.clone().injectBefore(p);
var a = clone.getLast ();
a.remove ();
var remove = document.createElement ('a');
remove.innerHTML = 'verwijderen';
remove.href = '#';
remove.addEvent ('click', function (e) {
e = new Event (e).preventDefault ();
this.getParent ().remove ();
});
clone.appendChild (remove);
var f = p.getFirst ();
f.value = '';
});
});
});
</script>
</head>

<body>
<div id="container">
<h1>Jan Koehoorn | <?php echo $title; ?></h1>
<p>Dit is een dynamisch multiple file upload script. Op deze manier kun je 1 of meer bestanden tegelijk uploaden.</p>
<p>JPG only, 50 KB max</p>
<?php
if (!empty ($errs)) {
echo '<ul class="errs">';
foreach ($errs as $err) {
echo '<li>' . $err . '</li>';
}
echo '</ul>';
}
if (!empty ($msgs)) {
echo '<ul class="msgs">';
foreach ($msgs as $msg) {
echo '<li>' . $msg . '</li>';
}
echo '</ul>';
}
?>
<form id="my_form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data">
<p>
<input name="userfile[]" type="file" size="60" /> <a class="add" id="toevoegen" href="#">toevoegen</a>
</p>
<p>
<input type="submit" value="upload" />
</p>
</form>
</div>
</body>
</html>

chechu
07-11-2008, 08:29 PM
Anyone, please ?