Home › Forums › Back End › Contact Form with Function to Add Attachment › Re: Contact Form with Function to Add Attachment
Hi guys,
again the same question as before.. but now i try to add the code to my current script but i cant get it to work… there is no error or so but the file just wont upload and send with the mail. below is the code can you pls help me out thanks
{
echo “Return Code: ” . $_FILES[“file”][“error”] . “
“;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “
“;
echo “Type: ” . $_FILES[“file”][“type”] . “
“;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb
“;
echo “Temp file: ” . $_FILES[“file”][“tmp_name”] . “
“;
if (file_exists(“upload/” . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . ” already exists. “;
}
else
{
move_uploaded_file($_FILES[“file”][“tmp_name”],
“upload/” . $_FILES[“file”][“name”]);
echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];
}
}
}
else
{
echo “Invalid file”;
}
function checkmail($mail)
{
// explode het e-mail adres op een @
$email_host = explode(“@”, $mail);
// pak alles na de @
$email_host = $email_host[‘1’];
// zet een var met de (eventuele) DNS van de domein
$email_resolved = gethostbyname($email_host);
// kijk of er een DNS aan zit en of alles voor en na het e-mail adres klopt
if ($email_resolved != $email_host && eregi(“^[0-9a-z]([-_.~]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$”,$mail))
$valid = 1;
// wanneer het geldig is, is $valid = 1, zo niet, dan geeft hij geen result (NULL)
return $valid;
}
function process_mail($data){
// get posted data into local variables
$EmailTo = “[email protected]”;
$Subject = “Mail vanuit website”;
$name = mysql_escape_string($data[‘name’]);
$tel = mysql_escape_string($data[‘tel’]);
$email = mysql_escape_string($data[’email’]);
$message = mysql_escape_string($data[‘message’]);
//validate the input
if(!isset($name) || $name == “”) $_SESSION[‘errors’][‘Naam’] = true;
if(!isset($tel) || $tel == “”) $_SESSION[‘errors’][‘Telefoon Nummer’] = true;
if(!checkmail($email)) $_SESSION[‘errors’][‘Email Adres’] = true;
if(!isset($message) || $message == “”) $_SESSION[‘errors’][‘Bericht’] = true;
//als er errors zijn gaan we stoppen met sturen van email!
if(sizeof($_SESSION[‘errors’]) > 0){
$_SESSION[‘error’] = true;
return;
}
//vorige errors verwijderen
unset($_SESSION[‘error’]);
unset($_SESSION[‘errors’]);
// prepare email body text
$Body = “”;
$Body .= “Name: “;
$Body .= $name;
$Body .= “n”;
$Body .= “Email: “;
$Body .= $email;
$Body .= “n”;
$Body .= “Tel: “;
$Body .= $tel;
$Body .= “n”;
$Body .= “Details: “;
$Body .= $message;
$Body .= “n”;
// send email
$success = mail($EmailTo, $Subject, $Body, “From: <$email>“);
if($success){
//generate auto reply!
mail($email, $Subject, “Beste $name,nnUw bericht is ontvangen door Chocolaterie Henrie.nWe zullen zo spoedig contact met u opnemen.nnMet vriendelijke groet,nn
Chocolaterie Henri
Tel: 013-5054939 | Email: [email protected]
“, “From: <$EmailTo>“);
} else {
$_SESSION[‘error’] = true;
$_SESSION[‘sysError’] = “Er is een fout opgetreden tijdens het versturen van het formulier. Probeer later nog eens”;
}
}
?>

Chocolaterie Henri
Helfheuvelpassage 118
5224 AP ‘s-Hertogenbosch
073 622 1994
“;
echo “
Uw bericht is verzonden.
“;
echo “
“;
session_destroy();
}
?>

Copyright© Chocolaterie Henri 2009 | Prijswijzigingen, en typefouten voorbehouden. by

hope to hear from you professionals soon
wing