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

Laravel News:
Laravel 5.7 Mail Localization Improvements
Oct 04, 2018 @ 14:18:41

In this new post to the Larvel News site, they cover some of the recent improvements in the mail handling for the framework, specifically in the use of localization to tailor the content for a certain language.

Laravel 5.7.7 is now released and includes both bug fixes and thanks to Derek MacDonald a big improvement to Mail Localization.

With the release of Laravel 5.7 the IlluminateNotificationsNotification class started offering a locale method to set the desired language. The application will change into this locale when the notification is being formatted and then revert back to the previous locale when formatting is complete.

The post provides an example of how to use this functionality in sending your emails and how to add a "locale" field to your models. This allows you to set up a preferred default locale for the data, removing the need to reference it directly every time.

tagged: mail localization improvement laravel tutorial example

Link: https://laravel-news.com/mail-localization

Freek Van der Herten:
How to send a "trial expiring soon" mail in Laravel Spark
Jan 15, 2018 @ 16:10:02

Freek Van der Herten has posted a guide to sending an email in a Larvel Spark-based system to remind a user that their trial of a service is expiring soon. In this case, it's a monitoring service he offers called Oh Deal.

I'm currently building a webapp named Laravel Spark, a Laravel based template to kick off SaaS projects. It offers logic for organising users into teams, handles trial periods, subscriptions, payments, invoices and much more.

[...] Unfortunately, Spark will not send out a mail to team owners whose teams are in trial periods that will soon expire. Luckily it's easy to add that yourself. I'll show you how to do just that in this post. Along the way, you'll learn some good general tips for sending out emails in batches. Let's get started!

He then starts in on the code, showing first how to locate the teams that should be sent the email. He adds a new field to track when the email was sent and the code required to send the actual email. He shows how to make the command restartable, create the "Mailable" class and the command to send the actual email.

tagged: team tutorial ohdear ending trial spark laravel mail email

Link: https://murze.be/how-to-send-a-trial-expiring-soon-mail-in-laravel-spark

Laravel News:
Homestead Now Includes Mailhog
Feb 10, 2017 @ 16:20:42

On the Laravel News site there's a new post covering a new inclusion into the Homestead VM: Mailhog:

A new Homestead base box has been released: Version 1.1.0. This release includes a new local mail handing system named Mailhog. The grunt-cli npm package is now installed globally, OPcache is now always invalidated, and finally we added some package-cleanup to the build process to lower the download size of the final compressed base box.

Long time Homestead users may remember that it previously supported the Ruby application, MailCatcher. By moving from MailCatcher to Mailhog the installation and configuration is easier than ever before.

They talk briefly about the steps needed to upgrade to Mailhog from MailCatcher and how to update your Homestead environment to take advantage of this latest change.

tagged: homestead mailhog virtualmachine mail mailcatcher

Link: https://laravel-news.com/homestead-now-includes-mailhog

Matt Stauffer:
Introducing Mailables in Laravel 5.3
Aug 05, 2016 @ 15:57:32

Matt Stauffer has posted the next in his "what's coming in Laravel 5.3" series today with this look at "mailables" to help make sending mail simpler in Laravel-based applications.

For the longest time, sending mail in Laravel has felt clumsy compared to the relatively light APIs of most other Laravel features. I'm not saying it's awful—it's still so much cleaner than its competitors--but it's often confusing to figure out what goes in the closure and what doesn't, what the parameter order is, etc.

Mailables are PHP classes in Laravel 5.3 that represent a single email: "NewUserWelcome", or "PaymentReceipt". Now, similar to event and job dispatching, there's a simple "send" syntax, to which you'll pass an instance of the class that represents what you're "dispatching"; in this context, it's an email.

He gives an example of the updated syntax for calling these "mailables", how to create them with the artisan command and their structure/usage. He also shows how to pass data into the object and some other included features (like customizing the delivery list, queuing and working with attachments).

tagged: mail sending laravel mailable class interface overview

Link: https://mattstauffer.co/blog/introducing-mailables-in-laravel-5-3

SitePoint PHP Blog:
Piping Emails to a Laravel Application
Feb 17, 2014 @ 15:13:48

On the SitePoint PHP blog there's a new tutorial posted about piping emails to Laravel (well, a Laravel-based application). He shows how to have your application take data in from the current input, parse it and insert the data into a database.

In project management or support management tools, you will see this a lot: you can reply to an email message and it is automatically visible in a web application. Somehow, these tools were able to get those email messages right into their system. In this article, we are going to have a look at how we can pipe emails to our Laravel 4 application.

He walks you through the creation of an Artisan command, "email.parse", and using the PHP MIME Mail Parser library to extract data. He gets the to, from, title and message contents from the email and shows how to work with attachments too. Finally, he shows how to set up the mail server to pipe the incoming email though the PHP script for parsing.

tagged: email parse message laravel tutorial mail server

Link: http://www.sitepoint.com/piping-emails-laravel-application/

Rob Allen:
Sending an HTML with text alternative email with ZendMail
Nov 02, 2012 @ 15:26:20

Rob Allen has a quick tutorial posted to his site today showing you how to send an email with the ZendMail component of the Zend Framework 2 that contains HTML but provides a plain text backup in the same message.

Sending a multi-part email with ZendMail is easy enough, but if you want to send an HTML email with a text alternative, you need to remember to set the content-type in the headers to multipart/alternative. As this is the second time I had to work this out, I'm noting it here for the next time I forget!

The rest of the post is the code you'll need to send a simple email with a text and HTML body sections, configure the headers (to, from, etc) and the "multipart/alternative" header to make the HTML or plain text switching work correctly.

tagged: zendframework2 mail tutorial send alternative html plaintext

Link:

Arvind Bhardwaj's Blog:
How to Test PHP Emails on Localhost
Jun 09, 2012 @ 17:02:20

In this quick tutorial Arvind Bhardwaj shows a method for testing your scripts that need to send emails, but on your localhost system.

While developing web applications on localhost you must have always missed the functionality to send mails. As localhost does not support email service, so it has always been a bottleneck for email testing on localhost. But I have found a simple way to test emails on localhost using PHP. I have overridden the default mail() function of PHP to create a text/html file based on the email format. If the email is in html format, an HTML file is created otherwise a text file is created. You can see in this file what exactly is the content sent in your mail. See how does it work.

He shows how to override the mail function with your own custom "mail" function, just in a difference namespace. He includes the sample code to send the email (the "mail" function), a basic HTML template you can use and and example of it in use.

tagged: mail localhost email tutorial testing

Link:

DreamInCode.com:
Preventing PHP Mail(...) Header Injections
Apr 22, 2011 @ 16:06:23

On the Dream In Code forums there's a recent post showing you how to prevent mail() header injections when taking user input, like from a form.

PHP's mail() function is a very useful and powerful function, even to the point that it is very easy to exploit. A way hackers exploit this function is a method called email header injection. [...] I'm sure most of you can already tell that's not going to be pretty since we didn't check the user input and so forth. PHP provides us with functions such as filter_var which will validate user input and either return false if the validation fails or return the filtered data.

He includes an example of using this filtering methods to check the user input for malicious information - validating that the "to" address is a valid email (FILTER_VALIDATE_EMAIL) and a sanitize() method that removes things like newlines, carriage returns and a few other characters.

tagged: prevent mail header injection tutorial filtervar sanitize

Link:

NetTuts.com:
How to Send Text Messages with PHP
Jan 25, 2011 @ 16:14:39

On NetTuts.com today there's a new tutorial showing you how to send text messages via SMS directly from your script to the user's cell phone.

Text messaging has become extremely widespread throughout the world — to the point where an increasing number of web applications have integrated SMS to notify users of events, sales or coupons directly through their mobile devices. In this tutorial, we will cover the fundamentals of sending text messages with PHP.

Their method "cheats" a little bit and uses an interface many of the cell phone providers offer to their subscribers - a link from an email address to SMS. Most providers have their domains you can send the email to and have it automatically forwarded to the user's cell as a text. Thankfully, this requires nothing more than the mail function to accomplish. They include the sample code and HTML+CSS to make a basic form as well as mention PHPMailer as a more powerful mailing alternative.

tagged: text message tutorial send phpmailer mail

Link:

PHPBuilder.com:
Downloading and Parsing Gmail Messages in PHP
Sep 01, 2010 @ 14:21:04

New on PHPBuilder.com today there's a tutorial showing you how to download and parse messages from Google Mail. In their case it's grabbing and parsing submissions from a form.

Some friends of mine publish a literary journal that accepts submissions via email. At their request I wrote a script to download messages from the journal's Gmail account and do some simple parsing tasks. Most of the submissions are made using an HTML form and a corresponding mailer script on their website, so I knew the precise format of the incoming messages (see Figure 1). What I didn't know was how to access Gmail in PHP.

He tried out the libgmailer script first, but ran into roadblocks until he realized he could use something PHP already had - the imap functions. With these he shows how to make a connection to the Gmail servers, get the listing of messages and pull out the body for the one you want to parse.

tagged: gmail google mail parse imap tutorial

Link:


Trending Topics: