Email Confirmation (in PHP)

Discussion in 'Web Design and Development' started by cwesty, Apr 19, 2006.

  1. cwesty macrumors member

    Joined:
    Oct 22, 2005
    #1
    Hello everyone.

    I'd like to be able to send email confirmation to users who submit a form on my site in php.
    Does anyone know how this is done?

    * I just simply want a very basic email message to be sent to a user, but can't seem to find what I'm looking for.

    Any help would be appreciated.
     
  2. Stampyhead macrumors 68020

    Stampyhead

    Joined:
    Sep 3, 2004
    Location:
    London, UK
    #2
    The mail function in PHP is pretty simple.

    mail($recipient, $subject, $message, $sender);

    You can define those variables earlier in the script or write the information in the function itself (i.e. mail(you@email.com, this is the subject, This is the message, me@email.com);)
    You can place it inside an if statement so that the email gets sent if the script is successful.

    Hope this makes sense, I'm writing this in a hurry.
     
  3. r1ch4rd macrumors 6502a

    r1ch4rd

    Joined:
    Aug 5, 2005
    Location:
    Manchester UK
    #3
    Something like this is what you are after.

    Code:
    
       $message = "Thank you for submitting a form";
       $email = $_POST["useremail"]
       $subject = "Form confirmation";
       $header = "From: email@yoursite.com\n"
       
       mail($email,$subject,$message,$header);
    
    
    You will have to make sure that mail is allowed by your webhost (it should be, but some free hosts disallow it) for this to work.
     
  4. Coolnat2004 macrumors 6502

    Coolnat2004

    Joined:
    Jan 12, 2005
    #4
    Also, if you want to have a verification system, you can generate a random code (the first few characters of an md5 checksum of a random string works well), store it in the database, send it with the email, and check that code against the one in the database when they go to verify. This is how I do it, anyway.

    And, on the side.. does anyone have a link that tells me how to send HTML e-mails with mail()?
     
  5. thejadedmonkey macrumors 604

    thejadedmonkey

    Joined:
    May 28, 2005
    Location:
    Pa
    #5
    HTML is a markup language, not a programming language. You can't send email with just HTML.
     
  6. Coolnat2004 macrumors 6502

    Coolnat2004

    Joined:
    Jan 12, 2005
    #6
    ....mail() being the mail() function in PHP, that is used to send email. I am asking how to send an HTML-formatted message with the mail() function in PHP..
     
  7. c-Row macrumors 65816

    c-Row

    Joined:
    Jan 10, 2006
    Location:
    Germany
    #7
    I think you can add this information to the "header" of your mail, like this:

    Code:
    $header  = "From: email@yoursite.com (Your Name)\r\n";
    $header .= "Content-Type: text/html\r\nContent-Transfer-Encoding: 8bit";
    Then HTML markups should work just like you use them in HTML pages.
     
  8. NoNameBrand macrumors 6502

    Joined:
    Nov 17, 2005
    Location:
    Halifax, Canada
    #8
    Make sure you do sanity checking, on the $sender variable especially, or some spammer bot is going to 'h4x0r' your script with an injection attack and use it to spam people.
     

Share This Page