Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile How Can I Use Php To Create A Mail Form And Automatically Send Information!

    I 'm building my personal website , I 'm gonna put 2 text boxes on my site so that anyone visits my website can leave their name and their email address there , and after they click "submit" or "send" , those information will be sent to my email address ... but someone said I need to know pHp to do that , but I don't ... so is there anyone here can help me the pHp code ? I 'll be very greatful !!!
    Sincere , Long
    Last edited by longinlos; 10-09-2004 at 04:27 AM.

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you know how to create an HTML form then this is super easy to do. PHP has a built-in function for sending mail. You can check out the function and some sample code at:

    http://us4.php.net/manual/en/function.mail.php

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I still get stuck !!!

    Thank you very much for replying to me , but honestly , I 'm using Dreamweaver to build my website , and I don't know much about the code , I only know some stuff to build a simple website and use some other scripts from the internet ... , so my problem is what should I do after I create 2 text boxes named "name" and "email address" and a "send" button ? How can I use pHp to get the value in those boxes and automatically sent to my mail box ?
    If you know the code , can you show me ? ... Thank you very much !!!
    Long

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the code...and in exchange you have to do something nice for a complete stranger today

    There are a million different variations on this but the following code will work if:
    1. You place it in a file name "index.php"
    2. You change the variable $yourEmail to equal whatever your real email address is
    3. Upload the file to a PHP web server with an SMTP port for outgoing mail enabled
    4. Open the file in a browser and submit the form

    -Hawkmoon
    PHP Code:
    <?
    error_reporting 
    (E_ALL E_NOTICE);
    $action     $_REQUEST["action"];
    $yourEmail "you@yourdomain.com";
    $email       $_POST["email"];
    $username $_POST["username"];

    if(
    $action=="sendEmail") {
      if(
    mail($yourEmail"Email Subject Line""The email for $username is $email")) {
        
    $str .= "Email Successful";
      } else {
        
    $str .= "Email Failure";
      }
    }

    $str .= "<form action='index.php?action=sendEmail' method='post'>";
      
    $str .= "<input type='text' name='username' value='{$username}'>";
      
    $str .= "<input type='text' name='email' value='{$email}'>";
      
    $str .= "<input type='submit' value='Send Email'>";
    $str .= "</form>";

    echo(
    $str);
    ?>

  • #5
    New Coder
    Join Date
    Oct 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you !

    Thank you so much , Hawkmoon ! Hopefully it works well ! I 'll try it !
    Best regards !
    Long

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by longinlos
    I 'm building my personal website , I 'm gonna put 2 text boxes on my site so that anyone visits my website can leave their name and their email address there , and after they click "submit" or "send" , those information will be sent to my email address ... but someone said I need to know pHp to do that , but I don't ... so is there anyone here can help me the pHp code ? I 'll be very greatful !!!
    Sincere , Long

    In the future please read our rules and posting guidelines before creating a topic.

    2) Type in a subject that summarizes your question- A great way to turn off other members wanting to help you is to type an incomplete or silly subject for your post. Examples of poor subject titles include:

    - "Help!"
    - "I'm a newbie...be gentle"
    - "How can I..."
    - "Urgent...deadline tomorrow!"

    The above subjects either have absolutely nothing to do with the question itself, or are grossly incomplete (ie: "How can I..."). When asking for help, enter a subject that summarizes your question, period! Don't use silly, incomplete, or "bait" subjects. Some examples of good titles are:

    - "How do I round a number to 2 decimal places using JavaScript?"
    - "What's the difference between require() and include() in PHP?"
    - "Can someone suggest a good, free HTML editor?"

    http://www.codingforums.com/rules.htm

    http://www.codingforums.com/postguide.htm
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    New Coder
    Join Date
    Oct 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To Spookster : I 'm sorry about that , I didn't know the rules !


    To Hawkmoon : I'm sorry to waste your time again , but it still doesn't work !
    The first thing I wonder is how can I know if the server support SMTP port or not , I 'm gonna use a free domain of www.netfirms.com , is that OK or I have to register a monthly paid domain ?
    Another problem is that I don't have any idea about the pHp code or any other as well ... I put those 2 text boxes and the button in my index.html , and as you said , I have to create a file index.php and put the code in the body tag , is that right ? , so how can I connect those 2 files together ? I mean how can I give the button the function to use the php code to send email after being pressed ?
    Thank you again , Hawkmoon !
    Best regards ! Long

  • #8
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey there... you REALLY need to learn some basics before you start asking tons of questions. I will make this as simple as possible:

    1. Create a new file called index.php in Dreamweaver
    2. Change the view from Design to Code in Dreamweaver
    3. Copy the code below and paste it into the code section of index.php
    4. Put your email address between the quotes where I wrote "CHANGE ME TO YOUR EMAIL ADDRESS"
    5. Save the file to a webserver
    6. Access the file through a browser

    That's it. You don't need to create the form or text boxes or any of that. The code I sent you has that. I'd really encourage you to pick up a beginner HTML or PHP book and start learning some of the basics.

    Have fun
    -Hawkmoon
    PHP Code:
    <html>
    <body>
    <? 
    error_reporting 
    (E_ALL E_NOTICE); 
    $action     $_REQUEST["action"]; 
    $yourEmail "CHANGE ME TO YOUR EMAIL ADDRESS"
    $email       $_POST["email"]; 
    $username $_POST["username"]; 

    if(
    $action=="sendEmail") { 
      if(
    mail($yourEmail"Email Subject Line""The email for $username is $email")) { 
        
    $str .= "Email Successful"
      } else { 
        
    $str .= "Email Failure"
      } 


    $str .= "<form action='index.php?action=sendEmail' method='post'>"
      
    $str .= "<input type='text' name='username' value='{$username}'>"
      
    $str .= "<input type='text' name='email' value='{$email}'>"
      
    $str .= "<input type='submit' value='Send Email'>"
    $str .= "</form>"

    echo(
    $str); 
    ?>
    </body>
    </html>


  •  

    Posting Permissions

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