Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Question I Am A Newby at This & Have a Simple Question For You


    I am working on putting a simple form on my site but I am unable to figure out how to have the completed form get emailed to the webmaster.

    Any ideas would be extremely appreciated.

    Thank you.

    Code:
    <!-- Form Code-->
    
    <form action="send_mail.php" method="post">
    <div style="float: left; margin-top: 5px; margin-left: 20px;">
    <input class="spotform1" onfocus=" if (this.value == 'Enter your name') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter your name';} " type="text" name="name" value="Enter your name" />
    <div style="clear: both;"></div>
    <input class="spotform1" onfocus=" if (this.value == 'Enter phone #') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter phone #';} " type="text" name="phone" value="Enter phone #" />
    <div style="clear: both;"></div>
    <div style="clear: both;"></div>
    </div>
    <div style="float: right; margin-top: 0px; margin-right: 20px;"><span style="float: left; margin-top: 0px; margin-left: 0px;">
    <input class="spotform2" onfocus=" if (this.value == 'Enter your email') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter your email';} " type="text" name="email" value="Enter your email" />
    </span>
    <div style="clear: both; height: 5px;"></div>
    <div align="right"><input class="contact1" style="color: #000; text-shadow: 0 1px 0 0 #fff;" type="image" value="Submit Your Info" /></div>
    <div style="clear: both;"></div>
    </div>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    13
    Rep Power
    0
    http://www.w3schools.com/php/php_mail.asp
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Please don't recommend w3schools, they're hopelessly out of date and usually wrong about things. See w3fools for information as to why.

    TheMilkMan, do you know PHP? You didn't post a single line of actual code, this is all just HTML markup. Do you have a page which accepts the form or anything?

    Comments on this post

    • tech0925 agrees
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    I do know this is HTML. The part I am stuck on is when the user inputs their information and then hits submit. There is a php code that is attached to this part of the html...

    Code:
    <form action="send_mail.php" method="post">
    Basically is grabs the info the user typed in the boxes and emails it to the webmaster.

    Am I way off base here?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    306
    Rep Power
    6
    The below code goes into the send_mail.php file you created.

    Code:
    if(isset($_POST['submit_now']))
    {
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$phone = $_POST['phone'];
    	
    
    
    $to = "webmaster@yourwebsite"; 
    
    // Your subject 
    $subject = "This goes to the webmaster"; 
    
    // From 
    $header = "Website Name or Email"; 
    
    // User info
    $messages ="You have received a new form submission. Below is their info. \r\r\r";
    
    $messages.="Name: $name \r\r";
    
    $messages.="Email: $email \r\r";
    
    $messages.="Phone: $phone \r\r";	
    
    		// send email 
    		mail($to,$subject,$messages,$header);
    }
    
    else {
    
    // enter your form here just incase the form is not properly submitted and a blank page doesn't show....
    
    }
    And add the name to the submit button like so:

    Code:
    <input class="contact1" style="color: #000; text-shadow: 0 1px 0 0 #fff;" type="image" name="submit_now" value="Submit Your Info" />
    The above code will email the webmaster only if the form is submitted. Of course you can go in further detail to make sure items are not empty but that is the basics..

    Comments on this post

    • ManiacDan agrees
    Last edited by tech0925; November 9th, 2012 at 10:12 PM.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    That didn't work. I changed that line of html and created and uploaded the php code you gave me.

    When I tested it, on the next page it gave me all the php you gave me across the top of the screen.

    What am I missing?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    306
    Rep Power
    6
    Originally Posted by TheMilkMan
    That didn't work. I changed that line of html and created and uploaded the php code you gave me.

    When I tested it, on the next page it gave me all the php you gave me across the top of the screen.

    What am I missing?

    All php must be wrapped like so:

    Code:
    <?php 
    
    // All php code in here
    
    ?>
    That tells the browser to treat the code as php. I just assumed you knew that.

    Don't wrap your html in it, just the php like so:

    Code:
    <?php
    
    if(isset($_POST['submit_now']))
    {
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$phone = $_POST['phone'];
    	
    
    
    $to = "webmaster@yourwebsite"; 
    
    // Your subject 
    $subject = "This goes to the webmaster"; 
    
    // From 
    $header = "Website Name or Email"; 
    
    // User info
    $messages ="You have received a new form submission. Below is their info. \r\r\r";
    
    $messages.="Name: $name \r\r";
    
    $messages.="Email: $email \r\r";
    
    $messages.="Phone: $phone \r\r";	
    
    		// send email 
    		mail($to,$subject,$messages,$header);
    }
    
    else {
    
    ?>
    
    Enter your form here just incase the form is not properly submitted and a blank page doesn't show....
    
    <?php
    
    }
    
    ?>
    Last edited by tech0925; November 9th, 2012 at 10:11 PM.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    Ha! Yeah that shows my knowledge of php.

    Now on the next screen after testing it says this...

    Code:
    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/rjjelley/public_html/rrr/send_mail.php on line 20
    
    Parse error: syntax error, unexpected T_STRING in /home/rjjelley/public_html/rrr/send_mail.php on line 20
    P.S. The site is on a subdomain... rrr.mywebsite.com

    Also, thank you very much for your fast replies. You are very helpful.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    I am pretty sure this is line 20...

    Code:
    $messages ="You have received a new form submission. Below is their info." \r\r\r";
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    306
    Rep Power
    6
    You are very welcome. Glad to help!

    Sorry, that was a typo. Change it to this:

    Code:
    $messages ="You have received a new form submission. Below is their info. \r\r\r";
    Last edited by tech0925; November 9th, 2012 at 10:13 PM.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    We must be getting closer. Now the next page after testing is just white. I the email has not come through.

    Could there be a problem with the html?

    How do I send them to a thank you page after submitting?

    Again, thank you.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    306
    Rep Power
    6
    Originally Posted by TheMilkMan
    We must be getting closer. Now the next page after testing is just white. I the email has not come through.

    Could there be a problem with the html?

    How do I send them to a thank you page after submitting?

    Again, thank you.
    Depending on your server and it may take a second or a few minutes. You should get it shortly. You can redirect to a new page or you can just simply make that same white page a thank you page like so..


    Code:
    Enter all the html that is above your form here..
    
    <?php
    
    if(isset($_POST['submit_now']))
    {
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$phone = $_POST['phone'];
    	
    
    
    $to = "webmaster@yourwebsite"; 
    
    // Your subject 
    $subject = "This goes to the webmaster"; 
    
    // From 
    $header = "Website Name or Email"; 
    
    // User info
    $messages ="You have received a new form submission. Below is their info. \r\r\r";
    
    $messages.="Name: $name \r\r";
    
    $messages.="Email: $email \r\r";
    
    $messages.="Phone: $phone \r\r";	
    
    		// send email 
    		mail($to,$subject,$messages,$header);
    
    ?>
    
    <p>Here you can place the html thank you message for submitting the form. This will only show if the submission was successful.</p>
    
    <?php
    
    }
    
    else {
    
    ?>
    
    <!-- Form Code This will only show if they reached this page without submitting the form. -->
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div style="float: left; margin-top: 5px; margin-left: 20px;">
    <input class="spotform1" onfocus=" if (this.value == 'Enter your name') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter your name';} " type="text" name="name" value="Enter your name" />
    <div style="clear: both;"></div>
    <input class="spotform1" onfocus=" if (this.value == 'Enter phone #') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter phone #';} " type="text" name="phone" value="Enter phone #" />
    <div style="clear: both;"></div>
    <div style="clear: both;"></div>
    </div>
    <div style="float: right; margin-top: 0px; margin-right: 20px;"><span style="float: left; margin-top: 0px; margin-left: 0px;">
    <input class="spotform2" onfocus=" if (this.value == 'Enter your email') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter your email';} " type="text" name="email" value="Enter your email" />
    </span>
    <div style="clear: both; height: 5px;"></div>
    <div align="right"><input class="contact1" style="color: #000; text-shadow: 0 1px 0 0 #fff;" type="image" name="submit_now" value="Submit Your Info" /></div>
    <div style="clear: both;"></div>
    </div>
    
    <?php
    
    }
    
    ?>
    
    Enter all the html that is below your form here...
    Notice that on this page I changed the form action so it submits to itself.
    Last edited by tech0925; November 9th, 2012 at 10:43 PM.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    306
    Rep Power
    6
    Ok,

    I just tested this out. The problem is the form submit type being set to image. I changed it to submit as you can see below:

    Here is the code:

    Code:
    Enter all the html that is above your form here..
    
    <?php
    
    if(isset($_POST['submit_now']))
    {
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$phone = $_POST['phone'];
    	
    
    
    $to = "webmaster@emailaddress.com"; 
    
    // Your subject 
    $subject = "This goes to the webmaster"; 
    
    // From 
    $header = "Website Name or Email"; 
    
    // User info
    $messages ="You have received a new form submission. Below is their info. \r\r\r";
    
    $messages.="Name: $name \r\r";
    
    $messages.="Email: $email \r\r";
    
    $messages.="Phone: $phone \r\r";	
    
    		// send email 
    		mail($to,$subject,$messages,$header);
    
    ?>
    
    <p>Here you can place the html thank you message for submitting the form. This will only show if the submission was successful.</p>
    
    <?php
    
    }
    
    else {
    
    ?>
    
    <!-- Form Code This will only show if they reached this page without submitting the form. -->
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div style="float: left; margin-top: 5px; margin-left: 20px;">
    <input class="spotform1" onfocus=" if (this.value == 'Enter your name') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter your name';} " type="text" name="name" value="Enter your name" />
    <div style="clear: both;"></div>
    <input class="spotform1" onfocus=" if (this.value == 'Enter phone #') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter phone #';} " type="text" name="phone" value="Enter phone #" />
    <div style="clear: both;"></div>
    <div style="clear: both;"></div>
    </div>
    <div style="float: right; margin-top: 0px; margin-right: 20px;"><span style="float: left; margin-top: 0px; margin-left: 0px;">
    <input class="spotform2" onfocus=" if (this.value == 'Enter your email') { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter your email';} " type="text" name="email" value="Enter your email" />
    </span>
    <div style="clear: both; height: 5px;"></div>
    <div align="right"><input class="contact1" style="color: #000; text-shadow: 0 1px 0 0 #fff;" type="submit" name="submit_now" value="Submit Your Info" /></div>
    <div style="clear: both;"></div>
    </div>
    
    <?php
    
    }
    
    ?>
    
    Enter all the html that is below your form here..
    Anytime you mark the submit type to image you need to include the image source as well. Since you are using inline CSS than you just need to change it to submit

    Place this code on your send_mail.php file

    Be sure to change the type to submit on the form page and make sure name="submit_now" is there as well.

    P.S. I noticed you are doing this:
    Code:
    <div style="clear: both;"></div>
    <div style="clear: both;"></div>
    There is no need to include two clear attributes together. One will do the trick
    Last edited by tech0925; November 9th, 2012 at 11:18 PM.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0
    That worked! ... Kind of.

    When I put, type="submit" it works but the button is cut in half.

    But when I put, type="image" the button is correct but then it doesn't email the form.

    This is weird.
  28. #15
  29. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Use type="image" and instead of $_POST['submit'] check $_POST['Submit_x'] (or possibly 'submit_x', I forget).

    This has really become an HTML question if your problem is an image button cut in half.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo