File Attachement via Email Script

the mail() function

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 14
Joined: Thu Mar 04, 2004 11:20 am

Tue Jun 08, 2004 6:56 pm

Hi There

I have a form, and a php mailing script that works great.

What i'm hoping to do is allow the user to attach a file with it.

this is what i have in my form.

Code: Select all

<input type="file" name="file">

this is my php mailing script:

Code: Select all




$from_who="Email <>";

$pagetitle="Contest And Contact";

if (getenv(HTTP_CLIENT_IP)){ 

else { 

$Contact = $_POST['Name'];
$Company = $_POST['CompanyName'];
$Address1 = $_POST['Address1'];
$Address2 = $_POST['Address2'];
$City = $_POST['CityTown'];
$Province = $_POST['Province'];
$PostalCode = $_POST['Postcode'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];

$mailbody.="Company Name:\n=================\n$CompanyName\n\n";

mail("$youremail", "$emailsubject", "$mailbody", "From: $from_who");  // Send the email.

$comments = nl2br($comments);

    echo"<p><font size=3 face=Arial, Helvetica, sans-serif><strong>Thank You. </strong></font></p>";

How can i get it to work by adding the file attachment

User avatar
php-forum Super User
php-forum Super User
Posts: 1279
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Tue Jun 08, 2004 7:43 pm

first you need to work with the "move_uploaded_file" and other file uploading functions...

then you need to encode the file... and set proper headers... to the mail...

I recommend you use

It is an excellent mailing tool

Post Reply