Contact form email Attachment.
I have a contact form on a website, and want people to be able to upload a small JPG photograph with it. Ideally the photo would be added to the email as an attachment.
This is my code at the moment:
PHP Code:
<?php
if(isset($_POST['submit'])) {
$to = "[I]Hidden[/I]";
$subject = "Pilot Card Application";
$title = $_POST['title'];
$first = $_POST['first'];
$last = $_POST['last'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$address = $_POST['address'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$option = $_POST['radio'];
$dropdown = $_POST['drop_down'];
$other = $_POST['other'];
$header = "From: $email <$email>";
$where = $_POST['where'];
$body = "Transport Pilot Application from $title $first $last\n\n Title: $title\n First Name: $first\n Last Name: $last\n\n Date of Birth: $day / $month / $year\n\n Address:\n$address\n\n Telephone Number: $tel\n Email: $email\n\n School: $dropdown\n Other: $other\n\n Data Protection: $option\n\n $first heard about the scheme from: $where";
echo
"<font=verdana><p align=center><b>Thank you for applying for the East Riding Youth Assembly's transport card. <br /> Somebody will get back to you within a few days.</p><br /><p align=center>If you have any further enquiries, please contact [email protected] or call 01482 392807</p></b></font>";
mail($to, $subject, $body, $header);
} else {
echo "blarg!";
}
?>
Re: Contact form email Attachment.
here is a complete example that sends mail with attachments using the mail() function.
Re: Contact form email Attachment.
I found this example to be more easily understandable and straightforward, but don't know if it's any "better" than the one kows linked to.
Because I've needed to send email with authentication (which cannot be done with PHP's mail() function alone), I adopted the free PHPMailer class where necessary. I mention it here because it can also be used to add attachments.