PHP
  Home arrow PHP arrow Sending Email with PHP Networking
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

Sending Email with PHP Networking
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-09-15


    Table of Contents:
  • Sending Email with PHP Networking
  • Sending mail with PHP
  • Application Code
  • Code Examined
  • Sending Mail using the PEAR::Mail

  • 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


    Sending Email with PHP Networking
    ( Page 1 of 5 )

    In this article we will look at the protocol that is involved in sending email messages. We will also examine the thorny issue of how to send an attachment with an email message. This article is the second of two parts.

    Setting up PHP to send email

    Before we do anything else, let's enable PHP to send email. This is a very simple process. Open up your configuration file and go to the section that deals with emailing. To save time, open up the find dialog box and enter "mail." This will take you to the mail section of the configuration file. It looks something like this:


    [mail function]

    ; For Win32 only.

    SMTP = localhost

    smtp_port = 25


    ; For Win32 only.

    ;sendmail_from = me@example.com


    ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").

    ;sendmail_path =


    You need to change the first two settings here, like so:


    SMTP = my.mailserver.com


    This is where you put the name of your outgoing mail server.

    The second setting is the return address that is sent with all your email messages, so change it to whatever email address you want there:

    ; For Win32 only.

    ;sendmail_from = myreturn@emailaddress.com


    These two settings are for Windows users. The third option is for Unix systems, as indicated in the configuration file. The default settings are usually correct and work most of the time. If these settings don't work, then your system or network administrator will be able to help.

    That's about it. So how does PHP help in sending email messages? PHP provides a function called mail(). This function takes the following arguments:

    • To - this is the email address to which the message goes.

    • subject - subject of the message.

    • Message - the actual message goes here.

    • Headers (optional) - Any extra headers, such as from, CC and BCC.

    The functions returns true if the message has been accepted for delivery and false if not. In its simplest form, you use the mail() function like so:



    <?php

    $to = " esme@holidays.com ";

    $subject= "Lunch?";

    $message = "This is my first test of the mail() function.";

    // Send

    $result=mail($to,$subject, $message);

    ?>




    With Headers it would look something like this:


    <?php

    $to = " esme@holidays.com ";

    $subject= "Lunch?";

    $message = "This is my first test of the mail() function.";

    $headers = 'From: webmaster@example.com' . "rn" .

    çc: webmaster@example.com' . "rn" .

    bcc: ac@milan.com;


    $result=mail($to, $subject, $message, $headers);

    ?>




     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





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