PHP
  Home arrow PHP arrow Page 4 - Managing Email
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Managing Email
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek