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

Laravel News:
Learn How to Send an Email on Error Exceptions
Apr 18, 2017 @ 10:25:03

On the Laravel News site there's a quick tutorial posted showing you how to send an email when an exception is thrown in your Laravel-based application using the "mailable" functionality.

You’ve created a new Laravel app for your client and deployed it on the production server. Everything was working fine till a customer has a problem with the app because of some buggy code. He immediately leaves the app, and the same thing happens with multiple customers before you know about the bug. You fix the bug, and then everything is on track.

But what if you were notified immediately through e-mail (or another service) about the bug and you fix it ASAP. In Laravel, this can be done easily and in this post, we’re going to learn how.

The post talks about how errors and exceptions are handled in Laravel applications and how, with a bit of custom code, you can create you own handler and a "mailable" class it can use (an ExceptionOccured mailer) to send a full stack trace when an error is thrown. There's also a link to a package that can be installed that helps to make setup even easier.

tagged: send email laravel exception tutorial mailable handler

Link: https://laravel-news.com/email-on-error-exceptions

Sending Email with SES in CakePHP 3
Dec 08, 2016 @ 09:31:21

The StarTutorial site has a new article posted showing you how to send email via SES in a CakePHP 3 application. SES is a service from Amazon Web Services that makes it simpler to send emails, the Simple Email Service (SES).

In this tutorial, we will show you how to set up CakePHP 3 to send email with AWS SES via SMTP. In our opinion, integrating AWS SES with CakePHP 3 by SMTP is more straightforward comparing to API.

They start off with the creation of the "EmailTransport" profile configuration dropped into the main application configuration file (defining connection and credential information). They then show how to create an "email profile" telling the framework to use the SES service definition. Finally they offer some advice about using the SES service on a Google Cloud instance and how to work around some of their port restrictions. CakePHP takes care of the rest, automatically understanding how to work with SES and using it transparently as the mailing service when you send your emails.

tagged: cakephp3 tutorial email aws ses send email configuration googlecloud

Link: https://www.startutorial.com/articles/view/sending-email-with-ses-in-cakephp-3

Freek Van der Herten:
Sending a welcome mail with Laravel 5.3
Oct 04, 2016 @ 11:15:35

Freek Van der Herten has posted a new tutorial to his site showing you a method for sending a "welcome" email for your Laravel (5.3) application using the recently added "mailables" functionality.

Recently I was working an a project where, in order to use the webapp, users should first apply for an account. Potential users can fill in request form. After the request is approved by an admin they may use the app.

Our client expected that the barrier to request an account should be very low. That’s why the request form doesn’t contain a password field. Instead, when an account is approved, a welcome mail is sent with a link to where the user can specify a password.

In this post I’d like to show you how we solved this with Laravel 5.3’s mailables.

He starts with a high level overview of what he's trying to accomplish: sending the approval when the admin approves a new user in the system. He includes all the code you'll need to create:

  • the "approve" method in the User model
  • the event handler for the "UserApproved" event
  • generating the password reset hash/token
  • the actual code for the mailable class to send the message

He also includes the view for the email's contents, a simple "WelcomeController" to handle the user responding to the message and the view for the verification and password reset "welcome" page.

tagged: laravel tutorial send welcome email approval mailable event

Link: https://murze.be/2016/10/sending-welcome-mail-laravel-5-3/

Laravel News:
Sending and Receiving SMS with Laravel and Nexmo
Aug 05, 2016 @ 12:36:05

On the Laravel News site they've posted a tutorial from Phil Leggetter showing you how to integrate your application with Nexmo to be able to send and receive SMS messages in your Laravel application.

In this quick tutorial by Phil Leggetter, we’ll cover how you can both send and receive SMS from your Laravel application. We’ll do this using Nexmo, a cloud communications platform that offers APIs for provisioning phone numbers, sending and receiving SMS (which is handy since we’ll use that), making and receiving phone calls and more.

He starts off with some prerequisites you'll need to get the system working (including an account on Nexmo and their command line tool). They create a fresh Laravel application and integrate the Nexmo PHP package into it as a service provider. With that installed he shows how to send an SMS message to a phone number, how to "rent" a number they can reply to and receiving the callback when they send a response. The post finishes with the setup of an "auto-responder" that just confirms that the message was received.

tagged: nexmo laravel tutorial integration send receive message rent number

Link: https://laravel-news.com/2016/08/sending-receiving-sms-laravel-nexmo/

Matt Stauffer:
Using SparkPost for Transactional emails with Laravel
Apr 27, 2016 @ 10:54:42

Matt Stauffer has a post to his site for the Laravel users out there wanting to seed "transactional emails" from their applications. In this tutorial he shows you how to use the SparkPost service to send emails with very little effort.

Recently, Mandrill announced that they'd be sunsetting their transactional email service and instead rolling it in to a secondary service for paid MailChimp users. That's fine for them, but many of us were using it for small one-off apps and weren't interested in all of a sudden paying money to send 100 emails a month.

[...] But right when Mandrill announced their pricing change, a new transactional email provider came out of nowhere: SparkPost. [...] So let's walk through the process of signing up and moving Giscus, my app for notifying you of comments on your gists, from Mandrill to SparkPost.

First he walks you through the process of getting a SparkPost account set up and configured to receive messages from your application. He then moves over to the Laravel side, upgrades his installed version and configures it with the "secret" value SparkPost provides and changes the MAIL_DRIVER value - that's basically it.. He also includes some screenshots of other parts of the SparkPost admin interface to show some of the other functionality included.

tagged: tutorial laravel sparkpost service transaction email send

Link: https://mattstauffer.co/blog/using-sparkpost-for-transactional-emails-with-laravel

SitePoint PHP Blog:
What is SparkPost?
Apr 25, 2016 @ 13:50:47

The SitePoint PHP blog has a post to their site introducing SparkPost, an email delivery service (in the same vein as Mandrill) that you can hook into your PHP applications to prevent the need to run your own mail servers.

I’ve used Mandrill for as long as I can remember. It sends transactional email, like the kind you receive when you sign up for a new account. Like me, many have been happy to use a free account for sending a relatively low number of emails a month. That is, until recently, when Mandrill caused a bit of a stir. The heart of the matter is that Mandrill removed their free tier. Anybody wishing to send mail through Mandrill now requires a paid-for MailChimp account

[...] Mindful that people are looking for alternatives (to power their personal newsletters or whatever), I spoke to Aydrian Howard. Aydrian is the Developer Advocate at SparkPost, whom I met at FluentConf. We talked for a bit about SparkPost and what makes it different from MailChimp.

After the little bit of Q&A about the service, the tutorial gets in and shows you how to get SparkPost set up for your application. They help you install their own client library and send a first test email using your account. Code is provided showing the configuration of the client with your key and the options you can define when sending the message.

tagged: sparkpost email send tutorial introduction mandrill

Link: http://www.sitepoint.com/what-is-sparkpost/

The Ultimate Guide to Sending Email in Laravel
Apr 01, 2016 @ 12:35:21

On the Scotch.io site today there's a new tutorial giving you the ultimate guide to sending emails in Laravel - from choosing your provider out to sending both text and HTML emails (some with attachments).

Sending emails in web applications has become so essential. Marketing, notifications, newsletters, adverts, etc are some of the reasons why we send emails to our clients. I'd say the majority of websites send automated emails at least via a "Contact us" form.

Let's explore the many possible ways to send emails in a Laravel application.

They start off with a brief look at three different services you can set up out of the box with Laravel: Mailgun (for regular sending), Mailtrap (for debugging) and Mandrill (for bulk emails). They show you how to configure each service in Laravel and setting one of them up as the default. The tutorial then gets into sending the actual emails through a simple EmailController::send endpoint. They show the code to set up the Mail. They show examples of what the resulting emails look like and how they show up in the related mail services. There's also instructions on attaching files, using queues to optimize email sending and a "bonus" about sending bulk emails with MailChimp.

tagged: send email laravel tutorial ultimate guide mailchimp mailtrap mailgun

Link: https://scotch.io/tutorials/ultimate-guide-on-sending-email-in-laravel

SitePoint PHP Blog:
Sending Emails in PHP with PHPMailer
Apr 27, 2015 @ 12: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/

Phillip Shipley:
Creating a PHP Nexmo API Client using Guzzle Web Service Client – Part 2
Apr 09, 2015 @ 11:58:38

Phillip Shipley has posted the second part of his series (first part is here) about creating a PHP client for the Nexmo API with Guzzle, the popular PHP HTTP client.

In Part 1 of this series we laid a foundation for consuming the Nexmo SMS API and covered a few ways to interact with it. In this part we’ll create the actual Guzzle Web Service Client to interact with it to demonstrate how simple it can be.

He starts by getting Guzzle installed via Composer including a few extra components: guzzle-services, retry-subscriber and log-subscriber. He defines the structure (code) for the message to send to the Nexmo service. Next up is the creation of the actual client that takes in configuration settings and extracts the HTTP location and applies the provided credentials to the connection. Finally he makes a simple SMS client that extends this base client and puts it to use with a simple message defined in an array (to, from and text contents). The client then reports back the results in a simple nested array with response information from the Nexmo API.

tagged: nexmo client guzzle webservice api part2 series connect send

Link: http://www.phillipshipley.com/2015/04/creating-a-php-nexmo-api-client-using-guzzle-web-service-client-part-2/

Rob Allen:
Sending attachments in multipart emails with ZendMail
Sep 16, 2014 @ 09: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/