Hunter Mitchell Hunter Mitchell - 1 year ago 95
HTML Question

Email Contact form

Ok, i have made a contact form. i need a php script to email me the information. Here is what i have so far:

$emailSubject = 'Contact Form';
$webMaster = 'email-here';

$firstName = $_POST ['first_name'];
$lastName = $_POST['last_name'];
$emailAddress = $_POST ['email'];
$uploadFile = $_POST ['datafile'];
$questions = $_POST ['comments'];

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
show_error("E-mail address not valid");

Ok, i have tried and tried to make one that will submit a uploaded file. i can not find anything. It is either to hard, or will not work. please help me.

Also, where it says:


is that where i put my input name?

Also, i have a thank you page. It is called: thank_you.html i need that to show up after the form is sent!

Answer Source
$to_name = stripslashes($_POST['to_name']);

$from_name = stripslashes($_POST['from_name']);

$subject = stripslashes($_POST['subject']);

$body = stripslashes($_POST['body']);

$to_email = $_POST['to_email'];

$attachment = $_FILES['attachment']['tmp_name'];

$attachment_name = $_FILES['attachment']['name']; 

if (is_uploaded_file($attachment)) { //Do we have a file uploaded?

  $fp = fopen($attachment, \"rb\"); //Open it

  $data = fread($fp, filesize($attachment)); //Read it

  $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed



//Let's start our headers

$headers = \"From: $from_name<\" . $_POST['from_email'] . \">\n\";

$headers .= \"Reply-To: <\" . $_POST['from_email'] . \">\n\"; 

$headers .= \"MIME-Version: 1.0\n\";

$headers .= \"Content-Type: multipart/related; type=\\"multipart/alternative\\"; boundary=\\"----=MIME_BOUNDRY_main_message\\"\n\"; 

$headers .= \"X-Sender: $from_name<\" . $_POST['from_email'] . \">\n\";

$headers .= \"X-Mailer: PHP4\n\";

$headers .= \"X-Priority: 3\n\"; //1 = Urgent, 3 = Normal

$headers .= \"Return-Path: <\" . $_POST['from_email'] . \">\n\"; 

$headers .= \"This is a multi-part message in MIME format.\n\";

$headers .= \"------=MIME_BOUNDRY_main_message \n\"; 

$headers .= \"Content-Type: multipart/alternative; boundary=\\"----=MIME_BOUNDRY_message_parts\\"\n\"; 

$message = \"------=MIME_BOUNDRY_message_parts\n\";

$message .= \"Content-Type: text/plain; charset=\\"iso-8859-1\\"\n\"; 

$message .= \"Content-Transfer-Encoding: quoted-printable\n\"; 

$message .= \"\n\"; 

/* Add our message, in this case it's plain text.  You could also add HTML by changing the Content-Type to text/html */

$message .= \"$body\n\";

$message .= \"\n\"; 

$message .= \"------=MIME_BOUNDRY_message_parts--\n\"; 

$message .= \"\n\"; 

$message .= \"------=MIME_BOUNDRY_main_message\n\"; 

$message .= \"Content-Type: application/octet-stream;\n\tname=\\"\" . $attachment_name . \"\\"\n\";

$message .= \"Content-Transfer-Encoding: base64\n\";

$message .= \"Content-Disposition: attachment;\n\tfilename=\\"\" . $attachment_name . \"\\"\n\n\";

$message .= $data; //The base64 encoded message

$message .= \"\n\"; 

$message .= \"------=MIME_BOUNDRY_main_message--\n\"; 

// send the message

mail(\"$to_name<$to_email>\", $subject, $message, $headers);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download