473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to send a resume to mail in php as attachment?

127 100+
i need to send a resume as attachment to a particular mail id...

its my form.
Expand|Select|Wrap|Line Numbers
  1. <form method="POST" name="email" action="sendmail.php" enctype="multipart/form-data" onsubmit="return validateForm()";>
  2.  
  3.     <table border=0 cellPadding=5 cellSpacing=10 width=100%>
  4.  
  5.         <tr>
  6.             <td><label for='name'>Name:</label></td>
  7.             <td><input  type="text" name="name" maxlength="50" size="30"></td>
  8.         </tr>
  9.          <tr>
  10.             <td><label for='familyname'>Family Name:</label></td>
  11.             <td><input  type="text" name="fname" maxlength="50" size="30"></td>
  12.         </tr>
  13.          <tr>
  14.             <td><label for='age'>Age:</label></td>
  15.             <td><input  type="text" name="age" maxlength="50" size="30"></td>
  16.         </tr>
  17.         <tr>
  18.             <td><label for='experience'>Years of Experience:</label></td>
  19.             <td><input  type="text" name="exp" maxlength="50" size="30"></td>
  20.         </tr>
  21.         <tr>
  22.             <td><label for='university'>University Attened:</label></td>
  23.             <td><input  type="text" name="university" maxlength="50" size="30"></td>
  24.         </tr>
  25.          <tr>
  26.             <td><label for='phone'>Phone Number:</label></td>
  27.             <td><input  type="text" name="phone" maxlength="50" size="30"></td>
  28.         </tr>
  29.         <tr>
  30.             <td><label for='resume'>Resume:</label></td>
  31.             <td><input type="file" name="resume"></td>
  32.         </tr>
  33.         <tr>
  34.             <td colSpan=2 align=center><input class=subbtn type="submit" value="Submit" name='submit' /></td>
  35.         </tr>
  36.  
  37.     </table>
  38. </form>
its my sendmail.php (without file attachment part)

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $name=$_POST['name'];
  3. $fname=$_POST['fname'];
  4. $age=$_POST['age'];
  5. $exp=$_POST['exp'];
  6. $university=$_POST['university'];
  7. $phone=$_POST['phone'];
  8.  
  9. $email_to='rajletsgetlost@gmail.com';
  10.  
  11. $emailsubject=ucfirst($name).' Resume';
  12. $body.="Hi,\n";
  13. $body.="Please find Mr.".$name." details below:\n\n";
  14. $body.="Name: ".$name."\n";
  15. $body.="Family Name: ".$fname." \n";
  16. $body.="Age: ".$age." \n";
  17. $body.="Experience: ".$exp." \n";
  18. $body.="University: ".$university." \n";
  19. $body.="Phone: ".$phone." \n";
  20.  
  21. mail("rajletsgetlost@gmail.com", $emailsubject,
  22.   $body, "From:" . $name);
  23.   header("location: thanks.php");
it works fine without attachment...

sendmail.php (file attachment part)

Expand|Select|Wrap|Line Numbers
  1. $fileatt =$_FILES['resume']['tmp_name']; // Path to the file
  2. $fileatt_type = "application/octet-stream"; // File Type
  3. $fileatt_name = $_FILES['resume']['name']; // Filename that will be used for the file as the attachment
  4.  
  5.  
  6. $file = fopen($fileatt,'rb');
  7. $data = fread($file,filesize($fileatt));
  8. fclose($file);
  9.  
  10.  
  11. $semi_rand = md5(time());
  12. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  13.  
  14. $headers .= "\nMIME-Version: 1.0\n" .
  15. "Content-Type: multipart/mixed;\n" .
  16. " boundary=\"{$mime_boundary}\"";
  17.  
  18. $body.= "This is a multi-part message in MIME format.\n\n" .
  19. "--{$mime_boundary}\n" .
  20. "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  21. "Content-Transfer-Encoding: 7bit\n\n" .
  22. $body. "\n\n";
  23.  
  24. $data = chunk_split(base64_encode($data));
  25.  
  26. $body.= "--{$mime_boundary}\n" .
  27. "Content-Type: {$fileatt_type};\n" .
  28. " name=\"{$fileatt_name}\"\n" .
  29. "Content-Disposition: attachment;\n" .
  30. " filename=\"{$fileatt_name}\"\n" .
  31. "Content-Transfer-Encoding: base64\n\n" .
  32. $data . "\n\n" .
  33. "--{$mime_boundary}--\n";
please help how to attach the file???
Dec 26 '13 #1
5 8564
Luuk
1,047 Expert 1GB
There's a nice library called phpmailer:
http://sourceforge.net/projects/phpmailer/

It will make your life easier.

There's even an example at their website:
a-simple-example
Dec 26 '13 #2
zmbd
5,501 Expert Mod 4TB
impin

BEWARE!
If you use third party software as suggested by Luuk, you do so at your own risk.
Dec 26 '13 #3
Luuk
1,047 Expert 1GB
yes, of course you do that at your own risk.....

But using PHP would that also not be, to him, 'using 3rd party software' ?

;-)
Dec 27 '13 #4
zmbd
5,501 Expert Mod 4TB
Luuk, Semantics; and by your reasoning so would the MS Windows operating system, UNIX (or its flavors), any browser, and so forth... besides you know what I mean by third party.

However, if not let me elucidate:
  • OP = 1st party
  • Members at this site providing open source guidance = 2nd party. The fact that the code is being reviewed by other members, experts, moderators, and admins provide some reassurance that OP should be provided generally safe code.
  • Links provided to pre-compiled code = 3rd party.
  • Worse, the link you provided now asks the referred party to goto yet another link. So from sourceforge now to github.

Technically, your post with the link is off topic as it does not directly answer OP's question; however, because it appeared to be shareware/freeware and fairly well used vs. commercial I didn't delete it... now, in retrospect perhaps I should have?
Dec 28 '13 #5
Luuk
1,047 Expert 1GB
@zmbd: thanks

@impin:
line 14:
Expand|Select|Wrap|Line Numbers
  1. $headers .= "\nMIME-Version: 1.0\n"
i dont think the initial "\n" should be there?
Dec 28 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: knoak | last post by:
Hi Pedro, I know i have to read a lot. :) But sometimes i need a little help from my friends, because i am the only one in my environment that experiments with php who could help me.. :( Few...
1
by: Fraser S | last post by:
Hi, I am receiving an invalid mail Attachment error when trying to send an attachment using System.Web.Mail. I have read other posts on these errors and have since checked that the asp.net account...
2
by: Cutlass | last post by:
Hello I'm using the following code to send mail from VB.NET 2003 oMail.SmtpServer = "xxx.xxx.com" Mailmsg.To = "joe@xxx.com" Mailmsg.From = "\Joe Blow\" Mailmsg.BodyFormat = MailFormat.Html...
0
by: JohnG | last post by:
Hi guys, Anyone give me a clue why this code doesn't work ------------------------------------- Public Function MailIt() On Error GoTo MailIt_Err DoCmd.SendObject acSendTable, "tblXXYY",...
1
by: bluewind44 | last post by:
Is there any way to send mail attachment from stream or binary? Because I design my solution to save files in DB not in physical files, I wanna send files to mail attachments directly. @.@
2
by: Robbie De Sutter | last post by:
Hello, How do I open a new, empty e-mail message from the default e-mail client whereby the sender is given and a file is attached? Currently I use the command (vb.net): ---...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
2
by: Ray | last post by:
Hi Can anyone help with something that has beaten me. I am sending an email with an attachment, as per below. If I comment out the MailAttachment line then the mail gets sent, but with it in I...
1
by: vinodkus | last post by:
dear sir/maadm I have to send a mail attachment but my problem is that file name of my attachment should be changed that i will write in a text box. please suggest any solution Thanks in...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.