Warning: Declaration of P_Photocrati_NextGen::define() should be compatible with C_Base_Product::define($id = 'pope-produ...', $name = 'Pope Produ...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/product.photocrati_nextgen.php on line 0

Warning: Declaration of M_Fs::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/module.fs.php on line 0

Warning: Declaration of M_Router::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/router/module.router.php on line 0

Warning: Declaration of M_I18N::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/i18n/module.i18n.php on line 0

Warning: Declaration of M_Validation::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/validation/module.validation.php on line 0

Warning: Declaration of M_WordPress_Routing::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/wordpress_routing/module.wordpress_routing.php on line 0

Warning: Declaration of M_Security::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/security/module.security.php on line 0

Warning: Declaration of M_Lzw::define($context = false) should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lzw/module.lzw.php on line 0

Warning: Declaration of M_NextGen_Settings::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_settings/module.nextgen_settings.php on line 0

Warning: Declaration of M_MVC::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/mvc/module.mvc.php on line 0

Warning: Declaration of M_Ajax::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ajax/module.ajax.php on line 0

Warning: Declaration of M_Dynamic_Stylesheet::define($context = false) should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/dynamic_stylesheet/module.dynamic_stylesheet.php on line 0

Warning: Declaration of M_Frame_Communication::define($context = false) should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/frame_communication/module.frame_communication.php on line 0

Warning: Declaration of M_DataMapper::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/datamapper/module.datamapper.php on line 0

Warning: Declaration of M_NggLegacy::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/module.ngglegacy.php on line 0

Warning: Declaration of M_NextGen_Data::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_data/module.nextgen_data.php on line 0

Warning: Declaration of M_Dynamic_Thumbnails::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/dynamic_thumbnails/module.dynamic_thumbnails.php on line 0

Warning: Declaration of M_NextGen_Admin::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_admin/module.nextgen_admin.php on line 0

Warning: Declaration of M_NextGen_AddGallery_Page::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_addgallery_page/module.nextgen_addgallery_page.php on line 0

Warning: Declaration of M_NextGen_Pagination::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_pagination/module.nextgen_pagination.php on line 0

Warning: Declaration of M_Gallery_Display::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_gallery_display/module.nextgen_gallery_display.php on line 0

Warning: Declaration of M_Attach_To_Post::define($context = false) should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/attach_to_post/module.attach_to_post.php on line 0

Warning: Declaration of M_NextGen_Other_Options::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_other_options/module.nextgen_other_options.php on line 0

Warning: Declaration of M_NextGen_Pro_Upgrade::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_pro_upgrade/module.nextgen_pro_upgrade.php on line 0

Warning: Declaration of M_MediaRss::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/mediarss/module.mediarss.php on line 0

Warning: Declaration of M_Cache::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/cache/module.cache.php on line 0

Warning: Declaration of M_Lightbox::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/lightbox/module.lightbox.php on line 0

Warning: Declaration of M_NextGen_Basic_Album::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_album/module.nextgen_basic_album.php on line 0

Warning: Declaration of C_NextGen_Basic_Album_Installer::install() should be compatible with C_Gallery_Display_Installer::install($reset = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_album/class.nextgen_basic_album_installer.php on line 0

Warning: Declaration of M_NextGen_Basic_Templates::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_templates/module.nextgen_basic_templates.php on line 0

Warning: Declaration of M_NextGen_Basic_Gallery::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_gallery/module.nextgen_basic_gallery.php on line 0

Warning: Declaration of C_NextGen_Basic_Gallery_Installer::install() should be compatible with C_Gallery_Display_Installer::install($reset = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_gallery/class.nextgen_basic_gallery_installer.php on line 0

Warning: Declaration of M_NextGen_Basic_ImageBrowser::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/module.nextgen_basic_imagebrowser.php on line 0

Warning: Declaration of C_NextGen_Basic_ImageBrowser_Installer::install() should be compatible with C_Gallery_Display_Installer::install($reset = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_imagebrowser/class.nextgen_basic_imagebrowser_installer.php on line 0

Warning: Declaration of M_NextGen_Basic_Singlepic::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_singlepic/module.nextgen_basic_singlepic.php on line 0

Warning: Declaration of C_NextGen_Basic_SinglePic_Installer::install() should be compatible with C_Gallery_Display_Installer::install($reset = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_singlepic/class.nextgen_basic_singlepic_installer.php on line 0

Warning: Declaration of M_NextGen_Basic_Tagcloud::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_tagcloud/module.nextgen_basic_tagcloud.php on line 0

Warning: Declaration of C_NextGen_Basic_Tagcloud_Installer::install() should be compatible with C_Gallery_Display_Installer::install($reset = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_tagcloud/class.nextgen_basic_tagcloud_installer.php on line 0

Warning: Declaration of M_Widget::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/widget/module.widget.php on line 0

Warning: Declaration of M_Third_Party_Compat::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/third_party_compat/module.third_party_compat.php on line 0

Warning: Declaration of M_NextGen_XmlRpc::define() should be compatible with C_Base_Module::define($id = 'pope-modul...', $name = 'Pope Modul...', $description = '', $version = '', $uri = '', $author = '', $author_uri = '', $context = false) in /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/nextgen_xmlrpc/module.nextgen_xmlrpc.php on line 0

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/product.photocrati_nextgen.php:0) in /home/sidesul6/public_html/wp-content/plugins/one-time-password/wp-otp-class.php on line 78

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/sidesul6/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/product.photocrati_nextgen.php:0) in /home/sidesul6/public_html/wp-content/plugins/one-time-password/wp-otp-class.php on line 78

Warning: Declaration of Walker_PostExpirator_Category_Checklist::start_lvl(&$output, $depth, $args) should be compatible with Walker::start_lvl(&$output, $depth = 0, $args = Array) in /home/sidesul6/public_html/wp-content/plugins/post-expirator/post-expirator.php on line 0

Warning: Declaration of Walker_PostExpirator_Category_Checklist::end_lvl(&$output, $depth, $args) should be compatible with Walker::end_lvl(&$output, $depth = 0, $args = Array) in /home/sidesul6/public_html/wp-content/plugins/post-expirator/post-expirator.php on line 0

Warning: Declaration of Walker_PostExpirator_Category_Checklist::start_el(&$output, $category, $depth, $args) should be compatible with Walker::start_el(&$output, $object, $depth = 0, $args = Array, $current_object_id = 0) in /home/sidesul6/public_html/wp-content/plugins/post-expirator/post-expirator.php on line 0

Warning: Declaration of Walker_PostExpirator_Category_Checklist::end_el(&$output, $category, $depth, $args) should be compatible with Walker::end_el(&$output, $object, $depth = 0, $args = Array) in /home/sidesul6/public_html/wp-content/plugins/post-expirator/post-expirator.php on line 0
How to Attach an Image to an Email Using PHP | SideApps

How to Attach an Image to an Email Using PHP

I recently wrote a small data acquisition system using PHP. I’m not a fan of web-based development and know very little but I had some financial incentive for this project and took it upon myself to learn along the way. By far the biggest headache I ran into was dealing with PHP’s mail() function. There’s obviously a reason so many third party libraries exist that tackle this issue but, being stubborn, I wanted to do it from scratch.

My goal was to generate and send an email consisting of an HTML body with an image attached. Embedding the image within the HTML turned out to be fairly trivial (in comparison) but an attachment was preferred. After MUCH ado I came up with the following function which does just that.

NOTE: This function doesn’t go to any extremes to validate itself and doesn’t make it past very many junk filters. This was fine for my use case as the email will be going to a single administrator who can easily whitelist the domain. However, if this is a concern I would highly recommend using one of the third party libraries as considerable configuration is required both in the PHP and on the delivering server itself.

Leave a Reply

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


Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in /home/sidesul6/public_html/wp-includes/functions.php on line 3297