Page 1 of 1

How to ATTACH and EMAIL file from a FORM to Email address

Posted: Tue Aug 31, 2010 3:01 am
by mozero
hello

I want to create a form in which the applicant can put his name, email and UPLOAD his CV then this data shud be emailed to an EMAIL address. I dont know how to EMAIL file attachment from a FORM to an Email Address. Can Anyone Help

Thanks

Re: How to ATTACH and EMAIL file from a FORM to Email addres

Posted: Tue Aug 31, 2010 4:28 am
by requinix
Look into PHPMailer.

Re: How to ATTACH and EMAIL file from a FORM to Email addres

Posted: Tue Sep 14, 2010 3:51 am
by mozero
hello i have tried so many things but not getting desirable results. following is the code i m using

PHP code

<?php


$strname=ucfirst($_REQUEST["strname"]);
$straddress=ucfirst($_REQUEST["straddress"]);
$strcity=ucfirst($_REQUEST["strcity"]);
$strstate=ucfirst($_REQUEST["strstate"]);


$phone=$_REQUEST["strno"];
if($phone != ""){ $strno=$phone; } else { $strno="-"; }

$stremail=$_REQUEST["stremail"];
$strcomments=ucfirst($_REQUEST["strcomments"]);


$strresume_name=$_FILES["strresume"]["name"];
$strresume_type=$_FILES["strresume"]["type"];
$strresume_size=$_FILES["strresume"]["size"];
$strresume_temp=$_FILES["strresume"]["tmp_name"];



if($strresume_type=="application/octet-stream" or $strresume_type=="text/plain" or $strresume_type=="application/msword" or $strresume_type=="application/vnd.openxmlformats")
{

$message= '


<table cellspacing="0" cellpadding="8" border="0" width="400">
<tr>
<td colspan="2"></td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strname.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$stremail.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>

</table>




';

// MAIL SUBJECT


$subject = "Mail with doc file attachment";

// TO MAIL ADDRESS


$to="muzaffaru@yahoo.com";

/*
// MAIL HEADERS

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Name <name@name.com>\n";

*/



// MAIL HEADERS with attachment

$fp = fopen($strresume_temp, "rb");
$file = fread($fp, $strresume_size);

$file = chunk_split(base64_encode($file));
$num = md5(time());

//Normal headers

$headers = "From:" .$strname. "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";

// This two steps to help avoid spam

$headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";

// With message

$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";

// Attachment headers

$headers .= "Content-Type:".$strresume_type." ";
$headers .= "name=\"".$strresume_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$strresume_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";



// SEND MAIL

@mail($to, $subject, $message, $headers);


fclose($fp);

echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#333333; font-weight:bold">Attachment has been sent Successfully.<br /></font>';
}
else
{
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Wrong file format. Mail was not sent.</font>';
//echo "<script>window.location.href='careers.html';</script>";
}

?>

HTML FORM

<form name="frm" method="POST" action="php/process.php" enctype="multipart/form-data">

<label for="Name">Name:</label>
<input type="text" name="strname">

<label for="Email">Email:</label>
<input type="text" name="stremail">

<label for="CV">CV (only .DOC files ):</label>
<input type="file" name="strresume"">

<input type="submit" name="submit" value="Submit" class="submit-button" onClick="return validate();" />
<input type="reset" name="reset" value="Reset" class="submit-button" onClick="document.feedback_form.reset();return false" />

</form>

Sometimes i get email from it sometimes not . i would be very thankful if some one can help me out in this. i just want to hav a form with NAME, EMAIL and CV upload features.

Thanks