comes the meat and potatoes. We set our Content-Type to image/jpg
along with the name of the file being sent, pretty straightforward
here, image/jpg tells the client we're sending this as a jpg
file and it has the name regal_004.jpg. We then insert a blank
line and here comes some tricky stuff.
run 2 functions on our $file string. Base64_encode and chunk_split.
Base64_encode basically just transforms our string of file
information into something that a mail client can more easily
read or as PHP.net puts it "This encoding is designed to make
binary data survive transport through transport layers that
are not 8-bit clean, such as mail bodies.".
then call chunk_split on that base64 encoded string. If you
were to var_dump the base64 string you'd see it go on forever
and ever, what chunking does is break it up after so many
characters so its easier for mail agents to read it. It defaults
to 76 characters so after every 76 characters its going to
break the line by adding \r\n to it. That's basically all
it does. So instead of a string like:
$string = "sdaflk;jasdfl;kjsadfl;jasljsdflkjsdf893u4tr89u8sduf89us98dfu98sduf98u8fu89sudf9usdfsdu89sdufsdf8fus89fusdfu8";
$new_string = chunk_split($string);