Search code examples
phpformsemailcheckboxmailto

Simple mailing form with check boxes


Venerable masters of all things code, I am a simple graphic (not even web) designer, struggling to creating a working mailing script.

So far, I managed to do it with basic HTML and a mailto function, but it needs to happen server-side, so, I am guessing PHP is my best bet.

Here's what I have so far:

<form action="mailto:?subject=Hello" method="POST" enctype="text/plain">
<input type="checkbox" name="Entry1" value="URL1">
<input type="checkbox" name="Entry2" value="URL2">
<input type="checkbox" name="Entry3" value="URL3">
<input type="checkbox" name="Entry4" value="URL4">
<label for="name">Name</label><input type="text" id="name" name="name" placeholder="Your Name">
<label for="email">Email(Required)</label><input type="text" id="email" name="email" placeholder="john_doe@example.com" required class="inputfield">
<input type="submit" id="search-submit" value="">
</form>

What I am trying to accomplish:

  1. An email to be sent from abc@email.com "email" field and a CC to 321@email.com
  2. With a message and Values (URL1,URL2...) from checked Boxes (Entry1,Entry2...)
  3. If successful, redirect to a thank you page.

Solution

  • <?php
    if(isset($_POST['send'])){
    
     $_POST['email'];
     $_POST['name'];
     @$_POST['Entry1'];
     @$_POST['Entry2'];
     @$_POST['Entry3'];
    @$_POST['Entry4'];
    
    $to      =  $_POST['email'];
    $subject = 'the subject';
    $message = $_POST['name'] . @$_POST['Entry1'] . @$_POST['Entry2'] .   @$_POST['Entry3']    . @$_POST['Entry4'];
    $headers = 'From:you@example.com';
    
    mail($to, $subject, $message, $headers);
    echo 'thanks you for your email';
    header("where_you_want.php");
    }else{
    echo 'please try again';
    }
    

    ?>

    <form action="where_you_want.php" method="POST" enctype="text">
    <input type="checkbox" name="Entry1" value="URL1">
    <input type="checkbox" name="Entry2" value="URL2">
    <input type="checkbox" name="Entry3" value="URL3">
    <input type="checkbox" name="Entry4" value="URL4">
    <label for="name">Name</label><input type="text" id="name" name="name"     placeholder="Your Name">
    <label for="email">Email(Required)</label><input type="text" id="email" name="email" placeholder="john_doe@example.com" required class="inputfield">
    <input type="submit" name="send" value="">
    

    this is not the best answer but I test it and sending email with value and you can     change value and play around..I hope its help..