Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Sending Emails in PHP with PHPMailer
Apr 27, 2015 @ 17:53:56

The SitePoint PHP blog has a tutorial from Narayan Prusty showing you how to effectively use PHPMailer to send emails from your PHP application. PHPMailer provides a simplified interface to send both simple and complex emails.

PHPMailer is one of the most popular open source PHP libraries to send emails with. It was first released way back in 2001 and since then it has become a PHP developer’s favorite way of sending emails programmatically, aside from a few other fan favorites like Swiftmailer. In this article we’ll talk about why you should use PHPMailer instead of PHP’s mail() function and we’ll show some code samples on how to use this library.

He starts by answering the obvious question - is it an alternative to PHP's own mail function? He describes the differences, mostly in the way of enhanced functionality PHPMailer offers. He then helps you get it installed via Composer and how to send a first simple email. Next up he shows how to send an email with attachments and connecting the library to an external SMTP server for sending. The tutorial finishes with a quick mention of using POP3 to read emails and how to show local error messages when something goes wrong.

tagged: tutorial send email phpmailer library simple attachment smtp pop3 error

Link: http://www.sitepoint.com/sending-emails-php-phpmailer/

Rob Allen:
Sending attachments in multipart emails with ZendMail
Sep 16, 2014 @ 14:18:09

Rob Allen has a new post today showing you how to use the ZendMail component of the Zend Framework 2 to send attachments with multipart emails. A multipart email allows you to combine both the HTML and plain text versions of the content into a single email.

I've written before about how to send an HTML email with a text alternative in ZendMail, but recently needed to send an attachment with my multipart email. With help from various sources on the Internet, this is how to do it.

He includes the full code for the example first: a "sendEmail" function that sets up the MIME and plain-text parts and uses the "MimeMessage" and "MimePart" objects to attach the file. He goes through each of the parts of the script and describes what's happening and how that changes the content of the email. You can find out more about the ZendMail component in this section on the Zend Framework manual.

tagged: tutorial send email attachment multipart zendframework2 zendmail

Link: http://akrabat.com/zend-framework-2/sending-attachments-in-multipart-emails-with-zendmail/

Sameer Borate:
Downloading Gmail attachments in PHP – an update
Jul 29, 2014 @ 14:37:40

Sameer Borate has posted an update to a previous post of his about downloading attachments in PHP. In this new post he updates the script to remove any other dependencies other than the IMAP PHP extension.

As mentioned in the earlier post, automatically extracting attachments from Gmail can be important for reasons where you need to process the attached files periodically with a CRON job or need to process the files programmatically. Also it can be useful for automatically archiving important attachments. [The code in this post] is a simple proof-of-concept plain PHP code, devoid of any object-oriented features that extracts attachments from your Gmail account.

The example code makes a request to the Gmail IMAP servers with the given username and password, grabs the first set of emails, parses their attachments to pull them down to the local host. He also includes some searching capability to locate ones only matching certain criteria. A list of the allowed search keywords is also included. He finishes the post with a look at using READONLY mode and fetching the email headers.

tagged: attachment download gmail tutorial search

Link: http://www.codediesel.com/php/downloading-gmail-attachments-in-php-an-update/

SitePoint PHP Blog:
Handle Incoming Email with SendGrid
Aug 27, 2013 @ 15:30:34

On the SitePoint PHP blog today Lukas White has a new tutorial showing you how to handle incoming emails from SendGrid (well, pulled from SendGrid) and translate them into posts for your blog or site.

In this article, I’m going to look at how you might implement an email-to-post feature, using SendGrid. SendGrid is a service for sending email – usually in bulk, but they also offer a less well-publicized feature for handling incoming email. SendGrid can be configured to handle all incoming messages for a given domain by pinging a URI of your choosing, and by implementing a simple webhook, you can act on the incoming mail accordingly.

He bases the simple example off of the Slim framework, creating a structure with a basic database for users and posts. He then goes through the SendGrid interface, pointing out where you add the hostname and URL to call back when a new email comes in. He includes the code to create the callback functionality that accepts the POST request coming from SendGrid. This is then validated and inserted into the database to be pulled out later by the "posts" page. There's also a bit about saving images (or other files) that come in as attachments to the email.

tagged: incoming email sendgrid callback post tutorial image attachment

Link: http://www.sitepoint.com/handle-incoming-email-with-sendgrid/

PHPMaster.com:
Exploring PHP’s IMAP Library, Part 2
Oct 04, 2012 @ 15:36:22

PHPMaster.com has published the second part of their series taking you on a tour through PHP's IMAP extension and its use. In part one they introduced the extension and showed how to connect, get the folders/emails and view message contents. In this part they expand n that and show you how to work with the messages and attachments.

In the first part of this series I discussed how to connect to IMAP servers using PHP’s IMAP extension. In this part we’ll complete the series by discussing working with folders and reading email content. Let’s get started!

He shows how to work with the "flags" set on messages (read, unread, replied, etc) - pulling them from the server and using the imap_setflag_full function to set them. There's a quick mention of deleting messages with imap_delete/imap_expunge and a section on viewing and downloading the attachments to messages.

tagged: imap library extension tutorial series attachment flags delete

Link:

Sameer Borate's Blog:
Downloading Gmail attachments using PHP
May 08, 2012 @ 14:08:40

Sameer Borate has a quick tutorial posted to his site today about using PHP, specifically the IMAP functionality, to grab attachments off of emails from Gmail.

Automatically extracting attachments from Gmail can be important for reasons where you need to process the attached files periodically with a CRON job. Also it can be useful for automatically archiving important attachments. Below is a simple proof-of-concept plain PHP code, devoid of any object-oriented features that extracts attachments from your Gmail account. It uses PHPs imap extension to access the inbox.

His simple script opens an IMAP connection to the Gmail server and loops through your current emails (max of 16) and tries to find any that have attachments. It then extracts this part of the message, base64_decodes it, and saves the set of them to the local file system. You can download the source here.

tagged: gmail attachment tutorial download imap

Link:

Gonzalo Ayuso's Blog:
Using a stream wrapper to access CouchDb attachments with PHP
Sep 06, 2010 @ 13:15:22

In his continuing look at using CouchDb as a file system, Gonzalo Ayuso has posted this third part in the group of articles about using streams to connect your scripts to the database instance.

I'm still working in my filesystem with CouchDb. After creating a library to enable working with PHP and CouchDB (see the post here), and after using Monkey Patching to override standard PHP's filesystem functions. I've created another solution now. Thanks to a comment in my last post (many thanks Benjamin) I've discovered that it's possible to create a stream wrapper in PHP (I thought it was only available with a C extension).

He includes the code for the stream connection wrapper, a pretty simple script that parses the string it's given and opens a read/write stream to the source. There's also a "url_stat" method that will return to you the size of the stream in bytes. Then you just register the wrapper and go about your normal file system calls to use the CouchDb directly.

tagged: couchdb stream wrapper attachment tutorial

Link:

Andrew Johnstone's Blog:
Emailing Attachments: Exim Filters and PHP streams
Jun 01, 2010 @ 13:51:28

New on his blog today Andrew Johnstone has a post about email attachments how how the combination of Exim filters and PHP streams can make things much easier for you and your application.

Using exim filters we could add attachments at the delivery stage, therefore reducing overhead in constructing and injecting data into an email. The delivery of emails varied as to whether it was feasible to send as a BCC or whether there were placeholders intended for each individual recipient. As such the following addresses the worst case scenario of attachments with placeholders intended for each individual recipient.

They show how to use a PHP script (that uses streams to pull in the file data and information) hooked into an exim_filter to streamline the attachment process. Configuration file examples are included in the post as well as the PHP source for creating the filter.

tagged: email attachment stream tutorial exim filter

Link:

NETTUTS.com:
CodeIgniter From Scratch: Day 3. Sending Emails and Attachments
Aug 04, 2009 @ 21:21:46

The NETTUTS.com site has posted the vidcast for the third day of their look at the CodeIgniter framework (and creating a full simple application with it).

At the request of some of our readers, this week, we'll examine just how easy it is to send emails with attachments using Gmail. With raw PHP, this would be a long and tedious task. However, with CodeIgniter, it's a cinch! I'll show you how in this eighteen minute video tutorial.

You can watch the video via their in-page player and grab the source code if you'd like to follow along.

tagged: tutorial email attachment codeigniter framework

Link:

DevShed:
Sending Email with PHP Networking
Sep 16, 2008 @ 16:21:23

DevShed has the second of a two part tutorial posted today on sending emails with the included mail() function.

In this article we will look at the protocol that is involved in sending email messages. We will also examine the thorny issue of how to send an attachment with an email message. This article is the second of two parts.

They include examples of sending simple messages and more complex ones with things like attachments and custom headers. They also tack on a look at the PEAR::Mail package to the end showing how it can make sending some things a little less painful.

tagged: email networking tutorial protocol simple complex attachment header

Link:


Trending Topics: