Like this code?
Show the author your appreciation.
send php mail with submitd form data and file attachment. Copy and paste these codes and change from and to mail address needed. Enjoy!!!!!!
careers.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="440">
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="2" style="text-align:justify; line-height:15px;" class="body">
<form name="frm" method="POST" action="careersuccess.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="23%" class="body"> Name</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strname" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Address</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="straddress"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> City</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strcity" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> State</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strstate" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Contact No</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strno" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Email</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="stremail" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Comments</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="strcomments"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Resume</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="file" name="strresume"></td>
</tr>
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="Send" name="submit" onClick="return validate();"> <input type="reset" value="Reset" name="reset">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
</table>
</body>
</html>
careersuccess.php
<?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" ]);
$filename = $_FILES [ "strresume" ][ "name" ];
$filetype = $_FILES [ "strresume" ][ "type" ];
$filesize = $_FILES [ "strresume" ][ "size" ];
$filetemp = $_FILES [ "strresume" ][ "tmp_name" ];
if( $filetype == "application/octet-stream" or $filetype == "text/plain" or $filetype == "application/msword" )
{
$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>Address</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $straddress . '</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>City</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strcity . '</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>State</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strstate . '</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>Contact No.</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strno . '</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>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Comments</strong></td>
</tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strcomments . '</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 = "to@mail.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 , "rb" );
$file = fread ( $fp , $strresume_size );
$file = chunk_split ( base64_encode ( $file ));
$num = md5 ( time ());
//Normal headers
$headers = "From: Name<name@name.com>\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: <" . $now . " 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>";
}
?>
cPanel Email Accounts Creator Categories : PHP , PHP Classes , Email , Form Processing , Web Services Protect your email links from being spidered by spam email robots! Categories : PHP , Security , Mail , Email Customer feedback or simple emailer - A PHP script that enables your visitors to send you emails.
Categories : PHP , Email , Form Processing send_mail function to defeat Header Injection Hacking/Spamming Categories : PHP , Email , Form Processing , Security Using this script anyone can easily get a form result to his/her mailbox. You can use this script for any form 2 mail purpose. Categories : PHP , Mail , Form Processing Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network , Email , PHP , PHP Classes Simple PHP Form Field Generator Categories : PHP , Beginner Guides , Form Processing , HTML and PHP XPertMailer - Sends TRUE Mails Categories : PHP , Mail , SMTP , PHP Classes PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP , Email , Beginner Guides , Filesystem mail -- send mail Categories : PHP , PHP Functions , Mail Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP , PHP , HTML , PDF , Excel Email Class Categories : PHP , Mail , PHP Classes PHPRecommend v1.0 - "Recommend this page to a friend" script written in
PHP. Easy to install Categories : PHP , URLs , Complete Programs , Email , Site Planning The Nearly Perfect Contact Us Form Categories : PHP , Form Processing , HTML and PHP imap_sort Categories : IMAP , Email , PHP , PHP Functions
vectorial pixel wrote : 1685
nice job... i like this thing!
Cristi Carstea wrote : 1718
Hello!
This is an impressive piece of code!
Still, has it`s own bugs.
When I try to send email attachements (I mean word file
= .doc) ,the email arrives as expected, but 2 unexpected
things happen:
1) the name of the attachement is always changed (still this is acceptable)
2) worse, when you look at the attachement, you will see
that it has lost it`s extension (doesn`t have any
extension at all) and when you try to open it you see that
the file is completely empty (Word sees nothing of what it
used to be on that file)
Can you please fix those 2 bugs?
Jenny Beaumont wrote : 1733
I'm having trouble adapting this to accomodate PDFs...any ideas ?
i've added $filetype=="application/pdf" and the attachment
comes through, but it adds an "r" on the end of my file,
plus, the whole email body layout get correupted. comes
through as code instead of html...
Amin Abbasian wrote : 1752
great code...
but i am receiving similar problem to that already mentioned.
1. attachment is received as a .DAT that when opened has no data.
and 2. how is it possible to alter this so users can send image files such as a jpeg or gif?
Please help me on this as I'm not too clued up on PHP!
Thanks!
Sasa Aleksandrov wrote : 1801
This would be correct code, and it's working as it should
be. Some variables wasn't declared or declared bad. Now
attachment is OK and have it's original name.
<?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" )
{
$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>Address</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $straddress . '</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>City</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strcity . '</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>State</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strstate . '</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>Contact No.</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strno . '</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>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Comments</strong></td>
</tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">' . $strcomments . '</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 = "some_mail@some_domain.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: yourname<youraccount@yourdomain.com>\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>";
}
?>
dev gona wrote : 1864
hey, can u please show me where i want to change the FROM and TO address please...
i tried but its not excuting please help me ASAP
nipen singha wrote : 1865
I could only submit if I have an attachment. Can you make it so the attachment is optional? Pl advise.
Nick Follows wrote : 1876
Thanks for this code it really is great though with one small problem...
The E-mails come through with the attachment correctly named and opens fine (as original) but the message body is empty. None of the data from the form fields has been sent through.
Also is it possible to send multiple documents in this way?
Eunice harkness wrote : 1891
Please can you contact me to do with changing the attachment to multiple attachment option in the form of jpg etc. My email address is eunice@harkness.co.za. Many thanx, will be eternaly grateful for your communication.
Dipesh Sejpal wrote : 1894
Hi,
It doesn't allow docx extension documents.
i want to inable doc,docx,text and pdf format.
Please help me.
Thank you for the script