PHP-Mail Functions

PHP contains two dedicated mail functions, which are built into PHP by default. The mail() function allows for the sending of email directly from a script, and ezmlm_hash() provides a hash calculation useful for interfacing a script to an  mailing list system.
The mail() function requires an installed and working email subsystem for sending mail. The program to be used is defined by configuration directives in the php.ini file. A common pitfall is that these are not set up correctly, rendering mail() inoperable. Note that the first two directives are for use only on Windows systems; the third is for use only on Unix-type systems.
  • SMTP: The host to which to connect to send mail. Can be either a fully qualified hostname or an IP address. Used only on Windows systems.
  • sendmail_from: The email address from which sent mail should appear to have been sent. Used only on Windows systems.
  • sendmail_path: Full pathname of the mail executable to run when sending mail. This can also include command-line arguments. The default is created during the precompilation configuration: For example, if a sendmail executable is found in /usr/sbin, the default will be usr/sbin/sendmail -t -i. If no sendmail executable is found, one must be specified here. Used only on Unix-type systems.

    mail

    bool mail(string recipient, string subject, string message, 
     [string extra_headers], [string extra_arguments]) 
    recipient
    Address of the recipient
    subject
    Message subject
    message
    Body of the message
    extra
    Extra headers for the message
    extra_arguments
    Extra arguments for the underlying mail program (PHP 4.0.5 and later)
    Sends a message via email.
    Returns:
    TRUE on success; FALSE on failure
    Description:
    mail() allows you to send email directly from a PHP script. recipient can be either a single email address or a comma-delimited list of addresses. If you want to set extra headers—for instance, in order to use Cc: or Bcc:—these may be placed in a newline-delimited string in the extra_headers parameter. As of PHP 4.0.5, you can also specify extra arguments to the system mail program in the extra_arguments parameter. For example, this is useful if you want to set the envelope From: header so that it doesn't look like email is coming from your web server daemon. If you do this, however, you may want to add your daemon process to the trusted users list in your sendmail configuration (if using sendmail); otherwise, sendmail will add an X-Authentication-Warning: header to the email, indicating that an untrusted user has modified the envelope.

    Send email from a PHP script

    /* When the following code was executed, I received this email: 
     * 
     * From: Apache httpd <www@pinc.com> 
     * To: torben@php.net 
     * Subject: This is a test 
     * Date: Mon, 20 Aug 2001 16:33:17 -0700 
     * 
     * Hi there, 
     * 
     * This is a test message. Please disregard. 
     */ 
    $address = 'torben@php.net'; 
    $subject = 'This is a test'; 
    $message = 'Hi there, 
    
    This is a test message. Please disregard. 
    '; 
    mail($address, $subject, $message); 
    
    /* Now, tell it that I want it to look like it's from me, using 
     * the extra_arguments parameter. 
     * The email I got back from this one was as follows. However, 
     * because this was run on a web page and the httpd is not a 
     * sendmail-trusted user, the resulting email also included this 
     
     * Subject: This is a test 
     * Date: Mon, 20 Aug 2001 16:47:56 -0700 
     * 
     * 
     * Hi there, 
     * 
     * This is a test message. Please disregard. 
     * 
     */ 
    mail($address, $subject, $message, '', 'ftorpden@php.net'); 
    
    /* Send the same message, but to a blind carbon-copy list. */ 
    mail($address, $subject, $message, 'Bcc: fif@bar.brz, king.ttrfgrut@abc.com'); 


Related Posts:
  • PHPGTK-application window PHPGTK is an extension to PHP that allows you to create graphical user interface (GUI) applications. Instead of running in a browser, your PHP application runs in its own application window. These applications are clie… Read More
  • php-Data Types Data Types PHP provides four primitive data types: integers, floating point numbers, strings, and booleans. In addition, there are two compound data types: arrays and objects.  Integers Integers are whole num… Read More
  • PHP-Http Environment Variables A Web browser makes a request of a Web server, it sends along with  the request a list of extra variables. These are called environment  variables, and they can be very useful for displaying dynamic content or… Read More
  • configuring PHP-impact security The primary mechanism for configuring PHP is the php.inifile. As the master file, this provides you with control over all configuration settings. Entries generally take the format:setting= value Be sure to read the comment… Read More
  • HTTP Request Methods-PHP !--#brandmenu { background: none repeat scroll 0 0 #f6f6f6; border-bottom: 2px solid #777; /*clear: left;*/ float: left; margin-top: 3px; padding: 0; position: relative; width: 78px; min-he… Read More
  • PHP-script-Related Variables PHP-script Related Variables PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are e… Read More
  • Make a PHP session code  Make a PHP session code session_start int session_start(void) Initializes a session. Returns: Always returns TRUE Description: Initializes a session. If a session ID is sent as a GET or in a cookie and is … Read More
  • top Database management system-PHP PHP Support for Multiple Databases  If you have been playing with PHP for a while, you have most likely noticed its excellent support for connecting to MySQL databases. Most of the PHP books on the market describ… Read More
  • PHP-max_execution_time php.ini Directives Related to the Connection-Handling Functions The following configuration directives can be used to control the behavior of the connection-handling functions. Directive Name Value Type Descri… Read More
  • php.ini Settings for Session Management Before you get started with this chapter, you may have to make a couple of minor changes to your php.ini file so that sessions work correctly. On Windows If you are using a Windows version of PHP, the first thing you… Read More
  • Manage Databases on a Server by php MySQL-related functions. mysql_list_dbs() Used to list the databases on a MySQL server. mysql_num_rows() Returns the number of rows in a result set. mysql_tablename() Despite its name, can extract the name of … Read More
  • PHP Online Resources The major sites that use PHP, and a listing of all the books written on PHP. Not only does this site contain a plethora of resources, it also contains links to the other PHP sites, the latest news about all things PHP … Read More
  • PHP-Mail Functions PHP contains two dedicated mail functions, which are built into PHP by default. The mail() function allows for the sending of email directly from a script, and ezmlm_hash() provides a hash calculation useful for interf… Read More
  • Networking Functions-PHP When using the PHP binaries for Windows that are available from http://php.net/, the getprotobyname(), getprotobynumber(), getservbyport(), and getservbyname() may not function as anticipated under Windows 2000. D… Read More
  • Advantages of MySQL and PHP Certain technologies play together better than others. PHP, a simple and powerful scripting language, and MySQL, a solid and reliable database server, make a perfect marriage between two modern technologies for building da… Read More