Send Mail With Attachment in PHP

if(isset ($_POST[“send”]))
$subject = $_POST[“subject”];
$separator = md5(time());
$eol = PHP_EOL;
$filename =’bankcopy.jpg’;

echo ‘<font style=”font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold”>Please fill all fields</font>’;
$fp = fopen($upload_temp, “rb”);
$file = fread($fp, $upload_size);

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

// main header
$headers = “From: “.$from.$eol;
$headers .= “MIME-Version: 1.0”.$eol;
$headers .= “Content-Type: multipart/mixed; boundary=\””.$separator.”\””;

$body = “–“.$separator.$eol;
$body .= “Content-Transfer-Encoding: 7bit”.$eol.$eol;
$body .= “This is a MIME encoded message.”.$eol;

// message
$body .= “–“.$separator.$eol;
$body .= “Content-Type: text/html; charset=\”iso-8859-1\””.$eol;
$body .= “Content-Transfer-Encoding: 8bit”.$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= “–“.$separator.$eol;
$body .= “Content-Type: application/octet-stream; name=\””.$filename.”\””.$eol;
$body .= “Content-Transfer-Encoding: base64”.$eol;
$body .= “Content-Disposition: attachment”.$eol.$eol;
$body .= $attachment.$eol;
$body .= “–“.$separator.”–“;

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

echo ‘<font style=”font-family:Verdana, Arial; font-size:11px; color:#333333; font-weight:bold”>Attachment has been sent Successfully.<br /></font>’;
<!DOCTYPE html>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Mail With Attachment</title>
<form id=”attach” name=”attach” method=”post” action=”<?php echo $_SERVER[“PHP_SELF”]; ?>” enctype=”multipart/form-data”>
<td>To</td><td>:</td><td><input type=”text” name=”to” id=”to”></td>
<td>Subject</td><td>:</td><td><input type=”text” name=”subject” id=”subject”></td>
<td>Message</td><td>:</td><td><input type=”text” name=”msg” id=”msg”></td>
<td>Attachment<span class=”imp”>*</span></td><td>:</td><td><input type=”file” name=”upload” id=”upload”></td>
<td></td><td></td><td><input type=”submit” value=”Submit” id=”send” name=”send”></td>

Similar Posts


  1. I leave a response whenever I appreciate a post on a site or I have something to add to the discussion. It’s triggered by the sincerness communicated in the article I browsed. And after this post %BLOG_TITLE%. I was actually moved enough to create a thought 😉 I actually do have a couple of questions for you if it’s allright. Could it be simply me or does it look as if like a few of the responses come across like left by brain dead visitors? 😛 And, if you are posting at additional online sites, I’d like to keep up with you. Could you make a list the complete urls of your shared sites like your twitter feed, Facebook page or linkedin profile?|
    I think this is among the most vital information for me. And i am glad reading your article. But should remark on some general things, The website style is ideal, the articles is really nice : D. Good job, cheers|
    It’s very easy to find out any matter on net as compared to textbooks, as I found this piece of writing at this web site.|
    Hello there! Would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would really appreciate your content. Please let me know. Many thanks|
    you’re in reality a just right webmaster. The web site loading pace is incredible. It sort of feels that you are doing any unique trick. In addition, The contents are masterwork. you’ve performed a wonderful job on this topic!|

  2. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?|
    You are so interesting! I don’t think I’ve read through a single thing like that before. So nice to discover another person with some genuine thoughts on this issue. Really.. many thanks for starting this up. This site is something that is needed on the internet, someone with some originality!|
    I got this web page from my pal who shared with me regarding this web page and now this time I am browsing this site and reading very informative posts at this time.|
    Please let me know if you’re looking for a author for your weblog. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some content for your blog in exchange for a link back to mine. Please send me an e-mail if interested. Regards!|
    Hi there terrific blog! Does running a blog similar to this take a lot of work? I have no expertise in programming but I was hoping to start my own blog soon. Anyway, if you have any suggestions or techniques for new blog owners please share. I understand this is off topic nevertheless I just needed to ask. Appreciate it!|

  3. Thank you first of all.
    Developing this kind of coding took more time. But you did very neat work to share this. Also it is much needed one too.

Leave a Reply

Your email address will not be published. Required fields are marked *