Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newb to php - email attachment question.

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
Hello all - I am new to php and am have created a flash file which uploads an image file to the server using the following php code:

Code:
<?php
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./files")) mkdir("./files", 0755); 
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);

?>

Now this works correctly and file is uploaded. Now I wanted the php code to automatically email this pic to an email address.

My typical php code for email sending is:
Code:
<?
if(!empty($_POST['sender_mail'])    
|| !empty($_POST['sender_message'])    
|| !empty($_POST['sender_subject'])    
|| !empty($_POST['sender_name'])){    
$to = "myemail@myemail.com"; // replace with your mail address    
$s_name = $_POST['sender_name'];    
$s_mail = $_POST['sender_mail'];    
$subject = stripslashes($_POST['sender_subject']);    
$body = stripslashes($_POST['sender_message']);    
$body .= "\n\n---------------------------\n";    
$body .= "Mail sent by: $s_name <$s_mail>\n";    
$header = "From: $s_name <$s_mail>\n";    
$header .= "Reply-To: $s_name <$s_mail>\n";    
$header .= "X-Mailer: PHP/" . phpversion() . "\n";    
$header .= "X-Priority: 1";    
if(@mail($to, $subject, $body, $header))    {        
echo "output=sent";    
} else {        
echo "output=error";    }
} else {    
echo "output=error";}
?>

I have attempted numerous times. but how do I combine the two so that my attachment will be emailed. Thanks so much for you help.

Jonathan
 
you need to set the right MIME headers and also encode the picture.
there is an FAQ in this forum that will set you in the right direction. I have also posted a complete multipart emailer script before.

but as Steve says: phpMailer is by far the easiest solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top