www.webdeveloper.com
Results 1 to 5 of 5

Thread: Mailto form HELP

Hybrid View

  1. #1
    Join Date
    Jul 2014
    Posts
    2

    Mailto form HELP

    Hi, Im just starting out doing anything with programming at 16 so I don't know a whole lot. But im trying to make a mailto form on a website (rtpsignsandgraphics.com). Specifically on the contact us page and everything looks fine and I don't see a problem in my code yet when i hit the submit button nothings happens and I have no idea whats wrong.rtpsignsandgraphics.com

    The problem is on the "Contact us" page. If anyone could help that would be great.

  2. #2
    Join Date
    Jul 2014
    Posts
    2
    Btw this is what the I have so far. Forgot to include in the message

    <form
    action="mailtomarsamara6@gmail.com" method="post" enctype="text/plain" >
    FirstName: <input type="text" name="FirstName">
    Email: <input type="text" name="Email">
    Message: <textarea cols="10" rows="6" name="comments"></textarea>
    <input type="submit" name="submit" value="Submit">


    </form>

  3. #3
    Join Date
    Jul 2014
    Posts
    2
    Hi Super,

    Firstly, like the other respondents have mentioned, you are using an outdated method for your form; furthermore, if you are just starting out, I would suggest you go with an html and php type form (or risk going insane learning the other languages mentioned herein). Meaning, your form elements will be in html, which will link to a php document with the server side coding required to have your form data emailed to you. Your HTML will look something like this:
    Code:
      <form name="contactform" method="post" action="send_form_email.php">
    					<div class="row half">
    						<div class="6u"><input type="text" class="text" name="name" placeholder="Name" /></div>
    						<div class="6u"><input type="text" class="text" name="email" placeholder="Email" /></div>
    					</div>
    					<div class="row half">
    						<div class="12u">
    							<textarea name="message" placeholder="Message:"></textarea>
    						</div>
    					</div>
    					<div class="row">
    						<div class="12u">
    							<ul class="actions">
    								<li><a href="MY PHP has a thank you html but if not, I could add the url to a thank you here" class="button form">Send Message</a></li>
    							</ul>
    						</div>
    					</div>
    				</form>
    Your PHP document should look something like this: (the php document for the form above is send_form_email.php and it's located in the same root folder as your contact form or web page containing the contact form html:
    Code:
    <?php
     
    if(isset($_POST['email'])) {
     
     
        $email_to = "yourname@yourdomain.com";
     
        $email_subject = "Add your custom subject line here";
     
         
     
         
     
        function died($error) {
     
            // your error code can go here
     
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
     
            echo "These errors appear below.<br /><br />";
     
            echo $error."<br /><br />";
     
            echo "Please go back and fix these errors.<br /><br />";
     
            die();
     
        }
     
         
     
        // validation expected data exists
     
        if(!isset($_POST['name']) ||
     
            !isset($_POST['email']) ||
     
            !isset($_POST['message'])) {
     
            died('We are sorry, but there appears to be a problem with the form you submitted.');       
     
        }
     
         
     
        $first_name = $_POST['name']; // required
    
        $email_from = $_POST['email']; // required
     
        $comments = $_POST['message']; // required
     
         
     
        $error_message = "";
     
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
     
      if(!preg_match($email_exp,$email_from)) {
     
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
     
      }
     
        $string_exp = "/^[A-Za-z .'-]+$/";
     
      if(!preg_match($string_exp,$first_name)) {
     
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
     
      }
     
      if(!preg_match($string_exp,$last_name)) {
     
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
     
      }
     
      if(strlen($comments) < 2) {
     
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
     
      }
     
      if(strlen($error_message) > 0) {
     
        died($error_message);
     
      }
     
        $email_message = "Form details below.\n\n";
     
         
     
        function clean_string($string) {
     
          $bad = array("content-type","bcc:","to:","cc:","href");
     
          return str_replace($bad,"",$string);
     
        }
     
         
     
        $email_message .= "First Name: ".clean_string($name)."\n";
     
        $email_message .= "Email: ".clean_string($email_from)."\n";
     
        $email_message .= "Message: ".clean_string($message)."\n";
     
         
     
         
     
    // create email headers
     
    $headers = 'From: '.$email_from."\r\n".
     
    'Reply-To: '.$email_from."\r\n" .
     
    'X-Mailer: PHP/' . phpversion();
     
    @mail($email_to, $email_subject, $email_message, $headers);  
     
    ?>
     
     
     
    <!-- Thank You!-->
     
     
     
    <!DOCTYPE HTML>
    
    <html>
    	
    THIS PORTION DELETED INTENTIONALLY - HERE IS WHERE YOU CAN PLACE YOU'RE OWN HTML THANK YOU CODE 
    
    </html>
     
     
     
    <?php
     
    }
     
    ?>



    Depending if you are coding HTML or HTML5, your root folder should contain: index.html (or your form document) and send_form_email.php - one displays the form and the php makes it work. For a deeper dive into the world of forms - download one of millions of usable templates on the web and play around with it.

  4. #4
    Join Date
    Jun 2014
    Location
    Cairns - Australia
    Posts
    81
    Dude the "mailto" method is way outdated.. I dont have Microsofts "Outlook Express" set up, so I cant even use your form...

    I do my mail in browser like gmail or yahoo.. anyone else like me cant either!.... Google around for tutorials.. Contact forms made in Javascript, Jquery, Ajax and php to get a design more for the here and now, not 1997

  5. #5
    Join Date
    Mar 2012
    Posts
    1,746
    "Mailto" is a simple (and largely obsolete) way of generating emails. It cannot be used to send form data (as you are trying to do). Also, the user input needs to be sanitized before it is used to generate an email. This is best done server-side, (e.g. in PHP) as javascript is insecure. As Code-tard has said, you need to Google for tutorials because the process is not straight forward. By all means raise a thread if you have a specific problem that you want help with...
    Last edited by jedaisoul; 07-22-2014 at 05:14 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles