SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTML form send with PHP

    <form action="post.php" method="post">
    <input type="text" name="name" placeholder="Име и Презиме" class="form-ime-i-prezime input-bidi-clen" autocomplete="off" required/><br>
    <input type="text" name="bday" placeholder="Датум на раѓање " class="form-godini input-bidi-clen" autocomplete="off" required/><br>
    <input type="e-mail" name="email" placeholder="Е-маил " class="form-e-mail input-bidi-clen" autocomplete="off" required/><br>
    <button type="submit" class="form-prati-kopce">Прати</button>
    </form>

    Hi.
    How can i send this form to my e-mail with php?
    Thanks.

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    On your post.php you will need to use the mail function.

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've used this snippet on a number of sites, seems to work ok.

    Place this code inside post.php or on the same page above the first <html> tag and post the form to itself.
    You might need to make a few tweaks to match your inputs, should give you a good start.

    PHP Code:
    session_start();

    $name '';
    $email '';
    $tel '';
    $comment '';
    $s_error_message '';

    if (isset(
    $_POST['submit'])) { //check for name of your submit button
      
    if (isset($_POST['name'])) {
        
    $name trim(stripslashes($_POST['name']));
      }
      if (isset(
    $_POST['email'])) {
        
    $email trim(stripslashes($_POST['email']));
      }
      if (isset(
    $_POST['tel'])) {
        
    $tel trim(stripslashes($_POST['tel']));
      }
      if (isset(
    $_POST['comment'])) {
        
    $comment trim(stripslashes($_POST['comment']));
      }
      if (
    strlen($name) == 0) {
        
    $s_error_message .= "&raquo; Enter your name<br>";
      }
      if (
    strlen($email) == 0) {
        
    $s_error_message .= "&raquo; Enter your email<br>";
      } elseif (!
    eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$"$email)) {
        
    $s_error_message .= "&raquo; Not a valid email<br>";
      }

      if (
    strlen($s_error_message) == 0) {
        
    $to "email@someaddress.com";
        
    $message "Name: " $name "\n\n" $comment "\n\nTel: " $tel "\nEmail: " $email;
        
    $subject "Website Query";

        if (
    mail($to$subject$message'From: ' $email)) {
          
    header('Location: http://www.yoursitename.com/thank-you.html');
        } else {
          print(
    'There was a problem sending the mail. Please check that you filled in the form correctly.');
        }
      }

    This will show any errors to the user, place in a div above the form.
    HTML Code:
    <strong><?php if (strlen($s_error_message) > 0) {print($s_error_message);} ?></strong>
    HTML Code:
    <form name="contact" method="post" action="post.php">
    		<fieldset>
    			<ol>  
    				<li>  
    					<label for="name">Name: <strong>required</strong></label>  
    					<input id="name" name="name" class="text required" type="text" value="<?php print htmlspecialchars($name); ?>">  
    				</li>  
    				<li>  
    					<label for="email">Email address: <strong>required</strong></label>  
    					<input id="email" name="email" class="email required" type="text" value="<?php print htmlspecialchars($email); ?>">  
    				</li>  
    				<li>  
    					<label for="tel">Telephone:</label>  
    					<input id="tel" name="tel" class="text" type="text" value="<?php print htmlspecialchars($tel); ?>">
    				</li>
    				<li>  
    					<label for="comment">Message:</label>  
    					<textarea id="comment" name="comment" class="text"><?php print htmlspecialchars($comment); ?></textarea>
    				</li>  
    			</ol>  
    		</fieldset>
    		<fieldset class="submit">  
    			<input name="submit" type="submit" value="Submit Message" class="submit">
    		</fieldset>
    		</form>
    Barry
    The more you learn.... the more you learn there is more to learn.

  4. #4
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried this code but it doesn't work because in php haven't any function to send to my e-mail.

  5. #5
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    This line sends the email:
    PHP Code:
     if (mail($to$subject$message'From: ' $email)) { 
    Did you customise the code to your email and website details?

  6. #6
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i customised for me but didn't work.
    And i use XAMPP.

  7. #7
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,435
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    If you are using XAMPP on a localhost you will need to set it up to send emails. I can not remember how at the moment.


Tags for this Thread

Bookmarks

Posting Permissions

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