PHP
  Home arrow PHP arrow Page 4 - Managing Email
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Managing Email
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2006-11-09

    Table of Contents:
  • Managing Email
  • MX Records
  • Other Emerging Technologies
  • Preparing PHP
  • Sending Email

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Managing Email - Preparing PHP


    (Page 4 of 5 )

    Before you can send email from your PHP script, you must first ensure that your copy of PHP has been correctly configured.

    If You Are Using PHP on UNIX

    To send email from a PHP script running on UNIX, you must have a sendmail-compatible MTA installed on the same server that your PHP script runs on.

    On UNIX systems, PHP sends email by running the command-line program

    sendmail. sendmail is the de facto standard MTA for UNIX systems.

    If you are using an alternative to sendmail, it must provide a sendmail wrapper. A sendmail wrapper is a drop-in replacement for the sendmail command-line program. It must accept the -t and -i command-line switches at the very least.

    When PHP is compiled, the configure script searches for the sendmail command in

     /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/
    lib

    If configure cannot find the sendmail command, then sendmail support will be permanently disabled. The following PHP functions will either be missing entirely, or will always return an error:

    • mail()—will be missing

    • ezmlm_hash()—will be missing

    • mb_send_mail()—will always return false

    When this happens, you must install a sendmail wrapper, and then recompile PHP.

    Once PHP is compiled with sendmail support enabled, whenever your script sends email, PHP will use the sendmail command discovered by the configure script. If you ever need to override this default, set the sendmail_path in php.ini to point to the sendmail command that you want PHP to use.

    sendmail_path = '/usr/local/bin/sendmail'
    If You Are Using PHP on Windows or Netware

    Although not documented in the PHP Manual, if you set the sendmail_path setting in your php.ini file, PHP will attempt to send email via the sendmail_wrapper—behaving exactly as if PHP were running on UNIX. This can catch you out, so remember to look for it when troubleshooting email problems.

    If you do not have a sendmail wrapper available, PHP on Windows talks to the mail transport agent (MTA) directly via the SMTP network protocol. PHP needs to be configured to tell it where to find your MTA:

    • The SMTP setting in php.ini must be set to the hostname (or IP address) of the email server that your MTA is running on. The default value is localhost. You will probably want to change that.

    • The smtp_port setting in php.ini must be set to the port that your MTA is listening on. The default value is 25. You probably will not need to change that.


    Note - It isn't documented in the PHP Manual, but PHP on Novell Netware uses the same code for email support as PHP on Windows.



    Caution - It is currently not possible to get PHP on UNIX to talk directly to the MTA via SMTP.


    PHP on Windows does not support SASL. If your MTA is configured to require authentication, you will need to change the security on your MTA to enable PHP to send emails through successfully.

    On UNIX, the MTA will automatically say that the email is from whichever user your PHP script is running as.

    This can't be done on Windows because PHP is connecting to the MTA over the network via SMTP. Instead, PHP will work out who the email is from by looking in these places in this order:

    • the from: header line passed to the mail() function

    • the sendmail_from setting in the php.ini file

    PHP will display an error and refuse to send the email if it cannot determine who the email is from.

    If you compile your own version of PHP on Windows, and you are going to use it to send emails, it's important that you build PHP with the Perl-compatible regular expression (PCRE) library included. PHP on Windows relies on the PCRE functions to make sure that headers have the correct end of line character. If you build PHP on Windows without PCRE support, you might find that MTAs refuse to accept your emails for delivery.

    With PHP correctly configured, you can now send email from your PHP scripts.

    More PHP Articles
    More By Sams Publishing


       · This article is an excerpt from the book "Zend PHP Certification Study Guide,"...
       · I am copying the email and the attachments to my computer so that even if I am not...
     

    Buy this book now. This article is excerpted from chapter 8 of the Zend PHP Certification Study Guide, written by Zend Technologies (Sams; ISBN: 0672327090). Check it out today at your favorite bookstore. Buy this book now.

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT