SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    May 2007
    Kent in Uk
    0 Post(s)
    0 Thread(s)

    form needs to send data to email


    I have created quite a primitive form using php. It sends a message to the person who has filled it in saying thank you and it also sends a message to 2 different website owners to let them know it has been filled in.
    I would also like the form to send the data from the form to one of the mail addresses. Can someone tell me how this can be done?

    My code is as below:

    <?php require_once("connection.php");
    $errors = array();
    $requiredfields = array('first_name'=> 'Please enter your FIRST NAME','surname'=> 'Please enter your SURNAME','email'=> 'Please enter your E Mail ADDRESS','text'=> 'Please enter your current needs');
    foreach($requiredfields as $fieldname => $requiredfieldsmessage){
    if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]) || strlen(trim($_POST[$fieldname])) == 0) {
    $errors[] = $requiredfieldsmessage;
     if(count($errors) == 0){ 
     $_POST = array_map('mysqli_prep', $_POST); 
    $first_name =  mysqli_prep($_POST['first_name']);
    $surname =  mysqli_prep($_POST['surname']);
    $email =   mysqli_prep($_POST['email']);
    $text =  mysqli_prep($_POST['text']);
    $query = "INSERT INTO form (first_name,surname,email,text)Values('{$first_name}','{$surname}','{$email}','{$text}')";
    $result = mysqli_query($connection, $query);
    $message="A contact form has been completed on";
    $subject="Solutionsinlaw contact form";
    $subject2="Solutionsinlaw contact form";
    $subject3="Solutionsinlaw contact form";
    $message2="Thank you for contacting us at Solutionsinlaw. We will get back you as soon as possible.";
    $message3="Thank you for contacting us at Solutionsinlaw. We will get back you as soon as possible.";
    mail($email2, $subject2, $message2);
    mail('', $subject3, $message3);
    header('Location: brief_return.php');
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <title>Contact Solutions in Law - Immigration Lawyers | USA Immigration Specialists London - UK </title>
    <meta name="description" content="Contact London, UK based an experienced immigration law attorney firm - Solutions in Law, Specializing in U.S. immigration, Visas, Green Cards & Citizenship. Call 44 020 3178 5419 today!">
    <meta name="keywords" content="USA Immigration, USA Visas, USA Immigration Lawyers,USA Green Cards, Green Cards, USA Citizenship, USA Migration, Live and Work in the USA, Work in the USA, US Immigration, US Visas, USA Immigration Attorneys, USA Residence">
        <meta HTTP-EQUIV="Content-Language" CONTENT="EN">
        <meta name="distribution" CONTENT="Global">
        <meta name="revisit-after" CONTENT="20 days">
        <meta name="robots" CONTENT="index,follow">
        <meta name="Googlebot" CONTENT="index,follow">
        <meta http-equiv='imagetoolbar' content='no'>
        <meta name='Rating' content='General'>
        <meta name='MSSmartTagsPreventParsing' content='true'>
        <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    	<script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-19198483-1']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    <!-- CSS -->
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script type="text/javascript">
        function changeClass(id, clas)
            document.getElementById(id).className = clas;
    <div id="content">
        <div class="header">
            <div class="floatleftt10"><a href="index.htm"><img src="images/logo.jpg" alt="US green cards, H1B, L1, B1, B2, visas, US Immigration"></a></div>
            <div class="floatrightt50"><p><span class="head_lgrey">TEL:</span> <span class="head_dgrey">(+44) 020 7969 2977&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="head_lgrey">EMAIL:</span> <span class="head_dgrey"></span></p>
            <div class="social"><a href="" target="_blank" title="Like us on Facebook"><img src="images/facebook.jpg" /></a>&nbsp;<a href="" target="_blank" title="Follow us on Twitter"><img src="images/twitter.jpg" /></a>&nbsp;<a href="" title="Find us on Linked in" target="_blank"><img src="images/linkedin.jpg" /></a>&nbsp;&nbsp;</div></div>
            <div class="clear5"></div>
               <div class="bg_head_menu">
                <div class="home"><a href="index.htm" class="menu_links">Home</a></div>
                <div class="about"><a href="about_solutions_in_law.htm" class="menu_links">About Us</a></div>
    			<div class="recruitement"><a href="international_clients.html" class="menu_links">International Clients</a></div>
    			<div class="recruitement"><a href="recruitment.htm" class="menu_links">Recruitment</a></div>
                <div class="recruitement"><a href="testimonials.html" class="menu_links">TESTIMONIALS</a></div>
                 <div class="recruitement"><a href="" class="menu_links">Latest News</a></div>
                <div class="contact"><a href="contact.htm" class="menu_links">Contact US</a></div>
    			<div class="contact"><a href="" class="menu_links">German Version</a></div>
        <div class="clear20"></div>
        <div class="site_content">
            <div class="col_left">
                <div><img src="images/main_img.jpg" alt="USA Immigration Attorneys, Employment, Business, Family and Education USA Visas" /></div>
                <div class="clear10"></div>
                <div class="floatleft"><h1 align="center">How can we help you?</h1>
                <p class="smalltext" style ="color:green">Our UK lawyers offer initial personal advice free of charge. Call 020 7989 2977<br> If you prefer you may </span> <a href="mailto:myemail" class="maintextlink">email us</a> or fill out the website form below and we will get back to you as soon as possible:</p></div>
                <div class="clear"></div>
                <div class="smalltext">
    if(count($errors) != 0){ 
    echo '<h3>Sorry, please address the following errors:-</h3>';
    echo '<ul>'; 
    foreach ($errors as $error) { 
    echo '<li>' . $error . '</li>';}echo '</ul>';
    <form style="padding:15px;" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    <p>First Name:<br/> <input type="text" size="30" name="first_name" value="<?php echo htmlspecialchars($_POST['first_name'],ENT_QUOTES); ?>" id="fname" /></p>
    <p> Surname:<br/><input type="text" size="30" name="surname" value="<?php echo htmlspecialchars($_POST['surname'],ENT_QUOTES); ?>" id="sname" /></p>
    <p>E mail:<br/><input type="text" size="40" name="email" value="<?php echo htmlspecialchars($_POST['email'],ENT_QUOTES); ?>" id="email" /></p>
    <p>How Can I help you?<br/>
      <textarea rows="10" cols="40" name="text"> <?php echo htmlspecialchars($_POST['text'],ENT_QUOTES); ?> </textarea></p><br />
      <input type="submit" name="submit" value="Submit " />
    Thanks for your help!

  2. #2
    Web developer chrisranjana's Avatar
    Join Date
    Jan 2001
    chennai , tamil nadu , India
    0 Post(s)
    0 Thread(s)
    so what is working and what is NOT working ?
    Chris, Programmer/Developer,
    Laravel Php Developers, Ruby on Rails programmers,
    Moodle, Opencart, Magento, Geodesic Classifieds/Auctions,

  3. #3
    SitePoint Evangelist
    Join Date
    May 2007
    Kent in Uk
    0 Post(s)
    0 Thread(s)
    Its all working. as I say I wan the form to send the information the form-filler puts into form sent in an email to the website owner. How can I do this? at the moment the email only notifies the website owner that a form has been filled in.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    Put this in one file and have a play with it.

    PHP Code:
    'My subject';

    $message var_export($_POST1);

    // OR uncomment these lines and use concatenation to build a string
    // $message = $_POST['a_test'];
    // $message .= $_POST['another_test'];  // <- note the .= (no space between them now)

    <form action="" method=POST>
    <input type=text name="a_test" value= "this is a test" />
    <input type=text name="another_test" value= "this is another test" />
    <input type=submit />
    Essentially, its that.

    You will want to pick off the POST values you want and filter their content carefully for bad things, and assemble readable output.


Posting Permissions

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