developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Web Hosting Directory
Shop Online
Dental Insurance
Corporate Awards
Computer Deals
Home Improvement
Compare Prices
Get Business Software
Cell Phones
Online Education
Logo Design
Server Racks
Logo Design
Imprinted Promotions

 


Storage Networking , Part 1
eBook: A storage network is any network that's designed to transport block-level storage protocols. But understanding the ins and outs of networked storage takes you deep into several of protocols. This guide covers SANs, Fibre Channels, Disk Arrays, Fabric, and IP Storage. »

Storage Networking 2, Configuration and Planning
eBook: Picking up where Part 1 left off, Part 2 of our look at storage networking examines configurations for SAN-attached servers and disk arrays, and also includes a look at the future of IP storage. »

Storage Management Costs in the Enterprise: A Comparison of Mid-Range Array Solutions
Whitepaper: Many factors contribute to the ownership cost for enterprise storage. These include (but are not limited to): physical capacity relative to physical space requirements, performance capacity for data transfer and system reaction time, software maintenance and updates, expandability and flexibility, and much more. »

Storage Is Changing Fast  Be Ready or Be Left Behind
PDF: The storage landscape is headed for dramatic change, thanks to new technologies like Fibre Channel over Ethernet (FCoE), pNFS, object-based storage and SAS that will affect everything from NAS and SANs to disk drives. Get the knowledge you need to make the most of your storage environment, now and in the future. »

HP StorageWorks EVA4400
Demo: Dont settle for an expensive and complex array that lacks functionality. The HP StorageWorks EVA4400 delivers virtual storage with enterprise class functionality at an affordable price. »

Developer News -
Linux Player Xandros Grabs Storied Rival Linspire    July 1, 2008
Hey Enterprise: Here Comes the 3G iPhone    July 1, 2008
MySpace Opens Profile Portability API    June 27, 2008
Microsoft Jumps Into Virtualization Fray    June 26, 2008
Free Tech Newsletter -

Access the RIA Development Resource Center: Get the latest news, insights, tips & resources to help you get up to speed in this emerging & exciting software development category.

Sending Email from your PHP Applications
By W. Jason Gilmore

Go to page: 1  2  Next  

Communicating with website users via email is crucial to the success of any online service. The ability to deliver registration confirmations and newsletters, provide a convenient and relatively secure password recovery tool, and keep clients updated with shipping status reports are just a few of the reasons for incorporating email-based features into your website infrastructure. In this tutorial, I'll show you how to incorporate email delivery capabilities into your PHP applications via both its native mail command and a great third-party extension called HTML Mime Mail. I'll conclude the article with a few pointers regarding how to most efficiently carry out bulk email delivery.

The mail() Function

Sending email via a PHP script is easy because PHP offers a native function called mail(). It accepts five parameters, three of which are required and the other two optional. The required parameters include the intended recipient, subject, and message. The optional parameters include additional mail headers and execution options for the mail delivery service. On Unix-based systems this service is by default Sendmail, although you can use other email services such as postfix or qmail, provided that you use sendmail wrappers available to each package. You can specify the location of this service by modifying the configuration directive sendmail_path. On Windows-based systems PHP requires the address of an SMTP server, specified with the SMTP configuration directive. The mail() function looks like this:

boolean mail(string to, string subject, string message 
[, string addl_headers [, string addl_params]])
Let's consider a simple example using the mail() function. The following script sends an email to jason@example.com:
<?php
   $to = "jason@example.com";
   $from = "support@example.com";
   $title = "Support subscription confirmation";
$body = <<< emailbody
Dear subscriber,

This email confirms your purchase of a 30 day
email support subscription. Please direct all 
requests to support@example.com.

Thank you,
The Example.com support staff

emailbody;
   $success = mail($to,$from,$title,$body,
              "From:$from\r\nReply-To:support@example.com");
?>

When taking advantage of the addl_headers parameter, keep in mind you'll need to Note that if you neglect to include the From header, the email will be sent by the Web server daemon owner. When using the Apache Web server, it's standard practice to use the user nobody or create a new user named apache or www for specifically this purpose. Therefore the above email sender address might look something like apache@example.com or www@example.com. Therefore, be sure to set this header value to lessen the possibility of confusion or accidental spam filtering.

The mail() function works great when you want to send just a simple email. However what about sending to multiple recipients? Sending HTML mail? Also, what about sending attachments? While you could use mail(), additional headers, and some additional programming to perform such tasks, there's another readily available solution that I'd like to introduce.

HTML Mime Mail

HTML Mime Mail is a very useful PHP class created and maintained by Richard Heyes (http://www.phpguru.org/). Available for free download and use under the BSD license, it's a fantastic class for sending MIME-based email. Offering an intuitive OOP syntax for managing email submissions, it's capable of executing all of the email-specific tasks discussed thus far, in addition to features such as handling attachments, sending plain-text emails, and sending HTML emails with embedded images. In this article I'll show you how to take advantage of this great tool.

Installing Mime Mail

HTML Mime Mail is available for download from Richard Heyes' website:
http://www.phpguru.org/static/mime.mail.html

Uncompress the file to a location preferably accessible by PHP's include_path setting. If this setting isn't available to you (for instance, you're using a shared server ISP), then uncompress it to a convenient location. Then include the class in your script using the REQUIRE_ONCE statement. In the following example I've placed the HTML Mime Mail directory in the same directory as my script:

require_once("htmlMimeMail5/htmlMimeMail5.php");
For this tutorial I'm using HTML Mime Mail version 2.5.1, which was rewritten for PHP 5. Take note that if you're still running PHP 4, you'll need to use an earlier version of the class.

Sending an Email

HTML Mime Mail's object-oriented interface makes sending email quite intuitive. In this first example I'll assign the sender address, subject, body text, and finally submit the message for delivery:

<?php

    require_once("htmlMimeMail5/htmlMimeMail5.php"); 

    // Instantiate a new HTML Mime Mail object
    $mail = new htmlMimeMail5();

    // Set the sender address
    $mail->setFrom("jason@example.com");
    
    // Set the reply-to address
    $mail->setReturnPath("jason@example.com");

    // Set the mail subject
    $mail->setSubject("Test HTML Mime Mail");

    // Set the mail body text
    $mail->setText("This is the body of the test email.");

    // Send the email!
    $mail->send(array("support@example.com"));

?>
As you can see, HTML Mime Mail offers a much more convenient means for creating and sending email messages than PHP's native interface. But this is just a sampling of this useful class's capabilities. Read on to learn more.

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


PHP Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Get enterprise phone service for a small biz price: Fonality solutions at Intel Business Exchange.
Are Your Threads Being Served Efficiently? Find out what your threads are up to. Click here.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES