Using mail() to attach image to email??
Posted: Tue Jun 03, 2008 9:40 am
I have a form that asks simply for name and phone number as well as an upload...
I want the end user to be able to upload an image and have that image sent as part of the email body!
I have managed to get the script working as far as taking the uploaded file and depositing it in a directory on the server....but I need to know how to then add the image just uploaded to the email $string.
Thank you in advance
I want the end user to be able to upload an image and have that image sent as part of the email body!
I have managed to get the script working as far as taking the uploaded file and depositing it in a directory on the server....but I need to know how to then add the image just uploaded to the email $string.
Thank you in advance
Code: Select all
<?php
$file_dir = $_SERVER['DOCUMENT_ROOT'] . '/terry/uploads/';
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['telephone'] ;
foreach($_FILES as $file_name => $file_array) {
if (is_uploaded_file($file_array["tmp_name"])) {
move_uploaded_file($file_array["tmp_name"], "$file_dir/".$file_array["name"]) or die ("Couldn't copy");
}
}
$string = "T-Shirt order form....\n\n\n";
$string .= "Name: ".$name."\n";
$string .= "Telephone Number: ".$phone."\n";
$string .= "T-Shirt Design"."\n\n";
mail("root@thanweb.co.uk", "Website - T-Shirt Order", $string, "From: root@thanweb.co.uk", "-froot@thanweb.co.uk");
header( "Location: http://www.thanweb.co.uk/thankyou.htm" );
?>