Log in

View Full Version : Php form auto respond



timmyblast
11-30-2012, 11:26 PM
Hi everyone,
Please i have a php script form that send attachement but i want it to also send an auto reply the users after filling out the form please can someone help me with the direction to do so, below is the php code for the form.. Thanks a million


<?php

function mail_file($to, $from, $subject, $body, $file){
$boundary = md5(rand());

$headers = array(
'MIME-Version: 1.0',
"Content-Type: multipart/mixed; boundary=\"{$boundary}\"",
"From: {$from}"
);

$message = array(
"--{$boundary}",
'Content-Type: text/plain',
'Content-Transfer-Encoding: 7bits',
'',
chunk_split($body),
"--{$boundary}",
"Content-Type:{$file['type']}; name=\"{$file['name']}\"",
"Content-Disposition: attachment; filename=\"{$file['name']}\"",
"Content-Transfer-Encoding: base64",
'',
chunk_split(base64_encode(file_get_contents($file['tmp_name']))),
"--{$boundary}--"
);

mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));


header('Location: contact-form-thank-you.html');

if (isset($_POST['firstname'], $_POST['lastname'], $_POST['company'], $_POST['address'], $_POST['phone'], $_POST['email'], $_POST['capacity'], $_FILES['file'])){
$body = <<<BODY
First Name: {$_POST['firstname']}
Last Name: {$_POST['lastname']}
Company Name: {$_POST['company']}
Address: {$_POST['address']}
Phone Number: {$_POST['phone']}
Email Address: {$_POST['email']}
Capacity: {$_POST['capacity']}

Details:
Name: {$_FILES['file']['name']}
Size: {$_FILES['file']['size']}
Type: {$_FILES['file']['type']}

BODY;


mail_file('sales@mydomain.com', 'sales@mydomain.com', 'AGENTS FORM', $body, $_FILES['file']);
}
?>

keyboard
12-02-2012, 02:37 AM
What do you mean by auto-reply the users?
Do you mean display some text in the users browser?
Just use echo inside the if statement.

Also, there's no validation on that... That script doesn't check if their email and so forth is valid.
Also, if all the fields aren't set, it'd just display an empty screen instead of telling the user to fill in all the fields... That might be something to look into.