Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Contact Form with Function to Add Attachment

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27060
    wingye
    Member

    Hi there,

    I have tried to find out a way to add attachment along with the mail form i have made, but things doesnt turn out as i wanted. As my php knowledge is not that great i am seeking for help here and hope to get the answer. My contact form look like this

    Code:
    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 Henri.nWe zullen zo spoedig contact met u opnemen.nnMet vriendelijke groet,nn
    A test page
    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-Contact

    Chocolaterie Henri

    Helfheuvelpassage 118
    5224 AP ‘s-Hertogenbosch
    073 622 1994

    Vul hier uw naam in.“; ?>
    Vul hier uw Email in.“; ?>
    Vul hier uw telefoonnummer in.“; ?>
    Laat uw bericht hier achter.“; ?>


    0){
    unset($_SESSION[‘error’]);
    unset($_SESSION[‘errors’]);
    }?>

    “;
    echo “

    Uw bericht is verzonden.

    “;
    echo “

    “;
    session_destroy();
    }
    ?>


    Chocolaterie Henri


    so what i do want it to have a button for the viewer to send a picture with the mail.

    i hope you guys can help me out

    Greets

    wing

#67449
TheDoc
Member

This looks like a pretty good tutorial:

http://apptools.com/phptools/forms/forms5.php

#67504
wingye
Member

Hi thanks for a quick reply, so if i am correct i can just use the code for attachment for my form ?

Code:
// generate a random string to be used as the boundary marker
$mime_boundary=”==Multipart_Boundary_x”.md5(mt_rand()).”x”;

// store the file information to variables for easier access
$tmp_name = $_FILES[‘filename’][‘tmp_name’];
$type = $_FILES[‘filename’][‘type’];
$name = $_FILES[‘filename’][‘name’];
$size = $_FILES[‘filename’][‘size’];

// here we’ll hard code a text message
// again, in reality, you’ll normally get this from the form submission
$message = “Here is your file: $name”;

// if the upload succeded, the file will exist
if (file_exists($tmp_name)){

// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){

// open the file for a binary read
$file = fopen($tmp_name,’rb’);

// read the file content into a variable
$data = fread($file,filesize($tmp_name));

// close the file
fclose($file);

// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}

// now we’ll build the message headers
$headers = “From: $fromrn” .
“MIME-Version: 1.0rn” .
“Content-Type: multipart/mixed;rn” .
” boundary=”{$mime_boundary}””;

that bit of code i should add to my form right..

#67919
wingye
Member

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

Code:
0)
{
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-Contact

Chocolaterie Henri

Helfheuvelpassage 118
5224 AP ‘s-Hertogenbosch
073 622 1994

Vul hier uw naam in.“; ?>
Vul hier uw Email in.“; ?>
Vul hier uw telefoonnummer in.“; ?>
Laat uw bericht hier achter.“; ?>




0){
unset($_SESSION[‘error’]);
unset($_SESSION[‘errors’]);
}?>

“;
echo “

Uw bericht is verzonden.

“;
echo “

“;
session_destroy();
}
?>


Chocolaterie Henri


hope to hear from you professionals soon

wing

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.