-2

My index.html page is at sapphirecrm.com and the code for the contact form looks like this:

    <div class="container">
        <div class="row">
            <div class="col-md-9 col-xs-12 forma">
                <form>
                    <input type="text" class="col-md-6 col-xs-12 name" name='name' placeholder='Name *'/>
                    <input type="text" class="col-md-6 col-xs-12 Email" name='Email' placeholder='Email *'/>
                    <input type="text" class="col-md-12 col-xs-12 Subject" name='Subject' placeholder='Subject'/>
                    <textarea type="text" class="col-md-12 col-xs-12 Message" name='Message' placeholder='Message *'></textarea>
                    <div class="cBtn col-xs-12">
                        <ul>
                            <!-- <li class="clear"><a href="#"><i class="fa fa-times"></i>clear form</a></li> -->
                            <li class="send"><a href="#"><i class="fa fa-share"></i>Send Message</a></li>
                        </ul>
                    </div>
                </form>
            </div>

I want to preserve the current styling of my send message button and just add the functionality so that when someone clicks on the send message button I will receive their info in my email inbox. I have a php script I wrote but I don't know where I am going wrong or how to add it to my html form so that when the button is clicked it will say "thank you" and then send me the emails:

<?php 

$name=$_POST['name'];
$email=$_POST['Email'];
$subject=$_POST['Subject'];
$message=$_POST['Message'];
$from = 'From: ContactForm'; 
$to = 'contact@sapphirecrm.com'; 
$data=$name . ", " . $email;
$file = "emails.csv";

file_put_contents($file, $data . PHP_EOL, FILE_APPEND);

$body = "From: $name\n E-Mail: $email\n Message:\n $message";



Print "Your Message Has Been Sent.";




?>

I already know I need to add a <form action="form_script.php" method="POST"> to the form tag in the html but what do I do after that? I am having trouble with the submit button and preserving the style when adding an <input type="submit" value="Send Message">

Razor
  • 1,778
  • 4
  • 19
  • 36

2 Answers2

3

It looks like you are looking for the mail() function.

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

The PHP manual: http://php.net/manual/en/function.mail.php

NovaLogic
  • 658
  • 13
  • 21
2

Replace the <a> with the <button> tag.

<ul>
    <li>
        <button type="submit" class="send"><i class="fa fa-share"></i>Send Message</button>
    </li>
</ul>
John Giotta
  • 16,432
  • 7
  • 52
  • 82