Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

File Attachement via Email Script

the mail() function

Moderators: macek, egami, gesf

File Attachement via Email Script

Postby redhead » 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
<?php

$youremail="cathoms@sympatico.ca"; 

$emailsubject="Contact";

$from_who="Email <cathoms@sympatico.ca>";

$pagetitle="Contest And Contact";

if (getenv(HTTP_CLIENT_IP)){ 
$user_ip=getenv(HTTP_CLIENT_IP); 

else { 
$user_ip=getenv(REMOTE_ADDR); 
}

$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.="Contact:\n=================\n$Name\n\n"; 
$mailbody.="Company Name:\n=================\n$CompanyName\n\n";
$mailbody.="Address:\n=================\n$Address1\n\n";
$mailbody.="Address\n=================\n$Address2\n\n";
$mailbody.="City:\n=================\n$CityTown\n\n"; 
$mailbody.="Province:\n=================\n$Province\n\n";
$mailbody.="Postcode:\n=================\n$Prostcode\n\n";
$mailbody.="Phone:\n=================\n$Phone\n\n";
$mailbody.="Email:\n=================\n$Email\n\n"; 
$mailbody.="File:\n=================\n$file\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
redhead
New php-forum User
New php-forum User
 
Posts: 14
Joined: Thu Mar 04, 2004 11:20 am

Postby ruturajv » 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

http://phpmailer.sourceforge.net

It is an excellent mailing tool
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.