1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Want to add name field to my contact form

Discussion in 'PHP & Perl' started by XoRaK, May 6, 2017.

  1. XoRaK

    XoRaK Regular Member

    Joined:
    Oct 28, 2009
    Messages:
    313
    Likes Received:
    251
    Occupation:
    social worker
    Location:
    Belgium
    Hi

    I have a form input field called 'name' and I want to send it through with the email I get when people hit send. There are two input fields in the form 'name' and 'email', now I jus get the email.

    CODE OF EMAIL.PHP SCRIPT (can't seem to find the button to put it as code on bhw...):



    $emailmanager = '[email protected]';
    error_reporting(0);

    $email = trim($_POST['email']);
    $Ok = ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);
    if ($Ok) {
    mail($emailmanager,'Subscribe to List','','From: '.$email);

    if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
    {
    ?>
    <script language = 'javascript'>
    alert('Thank you, your address was added to our Mailing List');
    history.go(-1);
    </script>
    <?
    exit();
    }
    }

    else {
    if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
    {
    ?>
    <script language = 'javascript'>
    alert('Sorry, please provide a valid Email address.');
    history.go(-1);
    </script>
    <?
    exit();
    }
    }
    ?>
     
  2. bl4cksta

    bl4cksta Registered Member

    Joined:
    Mar 6, 2017
    Messages:
    51
    Likes Received:
    6
    Gender:
    Male
    You need to set name to form element on name attribute.
    Code:
    $emailmanager = '[email protected]';
    error_reporting(0);
    
    $email = trim($_POST['email']);
    $name = trim($_POST['name']);
    $Ok = ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);
    if ($Ok) {
    mail($emailmanager,'Subscribe to List','','From: '.$name.' <'.$email.'>');
    
    if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
    {
    ?>
    <script language = 'javascript'>
    alert('Thank you, your address was added to our Mailing List');
    history.go(-1);
    </script>
    <?
    exit();
    }
    } 
    
    else {
    if(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
    {
    ?>
    <script language = 'javascript'>
    alert('Sorry, please provide a valid Email address.');
    history.go(-1);
    </script>
    <?
    exit();
    }
    }
    ?>
    
    http://php.net/manual/en/function.mail.php
     
  3. chenzen

    chenzen Jr. VIP Jr. VIP

    Joined:
    Aug 20, 2010
    Messages:
    119
    Likes Received:
    66
    in your field you must add name="name" to get $_POST['name']