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
Calling Cards
Corporate Awards
Promotional Pens
Domain registration
Auto Insurance Quote
Promotional Products
Best Price
GPS
KVM Switches
Imprinted Gifts
Online Education
KVM over IP
Baby Photo Contest
Car Donations

 


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 -

eKit: Web 2.0 Developer

Sending Email from your PHP Applications
By W. Jason Gilmore

Go to page: Prev  1  2  

Sending to Multiple Recipients

In the last example, you may have noticed the send() method requires that the recipient address is presented as an array element. This is because send() allows for emails to be sent to multiple users by simply appending new elements to the array. The following example sends an email to two users, namely jason@example.com and rosemarie@example.com:

// Send the email to editor@example.com
$result = $mail->send(array('jason@example.com', 'rosemarie@example.com'));

You can also specify other recipients in the same fashion using the setCc() and setBc() methods.

Sending an Attachment

The question of how to send attachments using PHP's mail() function comes up quite frequently in newsgroups. I'm happy to forego the gory details of how it's accomplished in this tutorial, because the HTML Mime Mail class resolves the problem quite easily. In the following example I'll send an email with an attachment titled htmlmimemail.doc to rosemarie@example.com:

<?php

    require_once("htmlMimeMail5/htmlMimeMail5.php");

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

    // Set the From and Reply-To headers
    $mail->setFrom("Jason <jason@example.com>");
    $mail->setReturnPath("jason@example.com");

    // Set the Subject
    $mail->setSubject("Test with attached email");

    // Set the body
    $mail->setText("Please find the new tutorial attached. Thank you!");

    // Retrieve a file for attachment
    $attachment = new fileAttachment("htmlmimemail.doc", "application/vnd.ms-word");

    // Attach the file, assigning it a name and a corresponding Mime-type.
    $mail->addAttachment($attachment);

    // Send the email to rosemarie@example.com
    $result = $mail->send(array('rosemarie@example.com'));
?>

Sending out HTML formatted email

Personally, I think receiving HTML-formatted email is akin to scratching one's nails on the blackboard. There's simply no reason for it. However there has been such an ongoing interest in learning how to do so programmatically that I don't think this tutorial would be complete without some discussion of the matter. Like attachments, sending HTML-formatted email with HTML Mime Mail is amazingly easy. The following example sends rosemarie@example.com an HTML-formatted email with a gray background and a GIF image named advertisement.gif. Note that the second (optional) parameter of the setHTML() method specifies the location of the images that should be embedded in the email. You also have the option of pointing the images to an online location, however keep in mind that some email clients (Squirrelmail for example) will not render these images for reasons of security.

<?php

    require_once("htmlMimeMail5/htmlMimeMail5.php");

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

    // Set the From and Reply-To headers
    $mail->setFrom("Jason <jason@example.com>");
    $mail->setReturnPath("jason@example.com");

    // Set the Subject
    $mail->setSubject("HTML formatted email");

    $html = "
    <body bgcolor='#808080'>
    <img src='advertisement.gif' alt='Buy my book!'>
    </body>";

    // Create the HTML email
    $mail->setHTML($html, "/home/apache/newsletter/images//");

    // Send the email to rosemarie@example.com
    $result = $mail->send(array('rosemarie@example.com'));

?>

Sending out Bulk Email

Web-based PHP scripts aren't designed to run for long periods of time (the default execution time is 30 seconds), and this presents a problem if you need to send a weekly newsletter to a large number of recipients. Therefore you'll want to consider alternative solutions for such purposes. These solutions not only facilitate subscriber management, but also support a wide variety of additional useful features such as auto-responses, web-based subscription/unsubscription, and web-based newsletter administration. As you might imagine, several open source software packages are available. I'll highlight two of the most popular packages here:

While these open source solutions are indeed powerful, both serve primary roles as mailing list administrators, and accordingly are lacking in a few features one might expect of a newsletter-specific application. For instance, scheduled mailings, response tracking, and custom HTML templates are just a few features that could greatly enhance the utility of this service. That said, if you have a budget available for purchasing third-party services, I suggest taking some time to evaluate a few commercial offerings. I'll highlight some of the more promising services here:

Alternatively you could take advantage of PHP's command-line interface (CLI), enabled by default as of version 4.3.0. Using the CLI, you can create scripts that execute directly from the command-line, or on a scheduled basis using a daemon such as CRON. PHP CLI scripts don't lack any of the features available to you when building Web applications, and have the additional advantage of being able to execute for a long period of time.

Conclusion

Communicating via email is a wonderfully effective and cheap means for enhancing your website's capabilities and keeping users updated regarding your organization's latest offerings. Using PHP and the great HTML Mime Mail class, doing so programmatically has never been easier. If you found this tutorial useful, I welcome you to email me with your comments and questions at wj AT wjgilmore.com. Thank you!

About the Author

W. Jason Gilmore (http://www.wjgilmore.com/) is the Open Source Editor for Apress (http://www.apress.com/). He's the author of Beginning PHP 5 and MySQL: Novice to Professional (Apress, 2004. 748pp.). His work has been featured within many of the computing industry's leading publications, including Linux Magazine, O'Reillynet, Devshed, Zend.com, and Webreview.

Go to page: Prev  1  2  


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.
View the Instruction Pipeline with AMD CodeAnalyst Performance Analyzer. Click here to learn more.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.
AMD CodeAnalyst Performance Analyzer integrates into Microsoft Visual Studio. Click here to learn more.
Business management in real-time, with real tools. Find Everest solutions at Intel Business Exchange.



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