Results 1 to 5 of 5

Thread: Sending An E-mail

  1. #1
    Join Date
    Jan 2008
    Location
    gods own country
    Posts
    2,319

    Smile Sending An E-mail

    Introduction

    One of the major uses of a server side scripting language is to provide a way of sending e-mail from the server and, in particular, to take form input and output it to an e-mail address. In this part I will show you how to send e-mail messages using PHP.

    The Mail Command

    Mail is extremely easy to send from PHP, unlike using scripting languages which require special setup (like CGI). There is actually just one command, mail() for sending mail. It is used as follows:

    mail($to,$subject,$body,$headers);

    In this example I have used variables as they have descriptive names but you could also just place text in the mail command. Firstly, $to. This variable (or section of the command) contains the e-mail address to which the mail will be sent. $subject is the section for the subject of the e-mail and $body is the actual text of the e-mail.

    The section $headers is used for any additional e-mail headers you may want to add. The most common use of this is for the From field of an e-mai but you can also include other headers like cc and bcc.

    Sending An E-mail

    Before sending your mail, if you are using variables, you must, of course, set up the variable content beforehand. Here is some simple code for sending a message:

    $to = "[email protected]";
    $subject = "PHP Is Great";
    $body = "PHP is one of the best scripting languages around";
    $headers = "From: [email protected]\n";
    mail($to,$subject,$body,$headers);
    echo "Mail sent to $to";

    This code will acutally do two things. Firstly it will send a message to
    [email protected] with the subject 'PHP Is Great' and the text:

    PHP is one of the best scripting languages around

    and the e-mail will be from
    [email protected]. It will also output the text:

    Mail sent to
    [email protected]

    to the browser.

  2. #2
    Join Date
    Sep 2008
    Posts
    5

    Default

    good tutorial.

    below line:
    echo "Mail sent to $to";

    should be imo:
    echo "Mail sent to ".$to;


    cheers mate.


  3. #3
    Join Date
    Sep 2008
    Posts
    4

    Default

    how to use it , i'm a young webmaster

  4. #4
    Join Date
    Dec 2008
    Posts
    5

    Default

    this is it :

    mail($to,$subject,$body,$headers);

    just you maybe have problem with smtp which in that case you must change
    2 or 3 lines in your php.ini

  5. #5
    Join Date
    Feb 2009
    Posts
    5

    Default

    thanks a lot

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •