Send mail in PHP script

Discussion in 'PHP' started by lokielookies, Mar 25, 2007.

  1. #1
    I have a little guestbook script. Visitors use a form to add their comments, their info and comments are written to a database, and they get displayed on a seperate page.

    Now I would like to have the script send an email to the admin whenever a new comment is posted.

    Can someone help me out?

    Greetz!
    Mieke
     
    lokielookies, Mar 25, 2007 IP
  2. Ekdal

    Ekdal Peon

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The simplest solution would be to add something like this:

    
    $to = "ENTER_YOUR_EMAIL";
    $subj = "ENTER_YOUR_SUBJECT";
    
    $guest = GET_GUEST_NAME_FROM_SUBMIT_FORM;
    $msg = GET_GUEST_MESSAGE_FROM_SUBMIT_FORM;
    
    $message = $guest." wrote:\n\n".$msg;
    $header = "From: $to\n";
    
    mail($to, $subj, $message, $header);
    PHP:
    You will of course need to replace GET_GUEST_NAME_FROM_SUBMIT_FORM, GET_GUEST_MESSAGE_FROM_SUBMIT_FORM with actual variables that holds that data.

    I suggest you google for php mail() tutorial and look a little deeper.
     
    Ekdal, Mar 25, 2007 IP
  3. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Download and use PHPMAILER Class.

    A best way to send mails.
     
    jitesh, Mar 25, 2007 IP