onSubmit - send form data to database & email

Discussion in 'PHP' started by bersude2, Dec 15, 2008.

  1. #1
    I have created a basic form whose database functionality works fine (upon submitting the form, the data is sent to the database). I am trying to ALSO send an email to myself saying that the information was submitted.

    I tried including onsubmit="mailto:email@mydomain.com" in the FORM tags, but nothing seems to be happening.

    I am running a Plesk 8.4 VDS with red hat 7 purchased through GoDaddy - do I need to setup backend pages within the server for php mail functions?

    someone PLEASE help, thanks!
     
    bersude2, Dec 15, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Short answer. Yes, you do.
    What you've included will do nothing (except maybe open the client's default email application.)

    http://php.net/mail
     
    Danltn, Dec 15, 2008 IP
  3. ubercreation.com

    ubercreation.com Banned

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmm, you need to look at php's default mail function just like what the poster above says
    ex: mail('recipient@mail.com','subject','body');
     
    ubercreation.com, Dec 15, 2008 IP
  4. ksamir2004

    ksamir2004 Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you have login through mail id then

    $to =$_COOKIE['mail']; // static mail id here seperated comma if youo want to insert more email
    $subject = "Subject Name";

    $headers = "MIME-Version: 1.0\r\n";
    $headers = "From: Portal name <from address here>\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $body ="<p>Hello ".$names."</p><p>Your data for portal is: ".$newdata." </p><p><p>Thank You</p> <p>This is Auto generated mail from <domain name></p>";
    mail($to,$subject,$body,$headers);
    setcookie("top", "Thanks For Submitting data", time()+3600);
    header("Location: http://url address");
     
    ksamir2004, Dec 16, 2008 IP
  5. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #5
    If he is sending the mail to himself, as per OP then you don't need to retrieve the email address from a cookie, rather hard coding it into the application.
     
    chopsticks, Dec 16, 2008 IP
  6. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
      $message='User: '.$username."\n\n";
      $message.='They just submitted the form to the database';
      $headers='From: My Site <me@mysite.com>'."\r\n";
      $headers.='Reply-To: My Site <me@mysite.com>'."\r\n";
      mail("me@mysite.com","Data Submitted",$message,$headers);
    Code (markup):
     
    Yesideez, Dec 16, 2008 IP