1

i I've been trying to get a .php that works with this HTML code for my website (template), I tried using my old .php from my old website and changing the details but that sadly lead to no avail.

I am clueless when it comes to .php and would really appreciate your help!

What would my .php have to contain?

<form action="#" id="contact-form">
    <div id="success"></div>
    <ul>
    <li class="input-name">
        <input type="text" id="name" class="required" placeholder="Name">
    </li> <!-- END input-name -->
    <li class="input-email">
        <input type="text" id="email" class="email" placeholder="Email Address">
    </li> <!-- END input-name -->
    <li class="input-subject">
        <input type="text" id="subject" placeholder="Subject">
    </li> <!-- END input-name -->
    <li class="input-subject">
        <textarea rows="7" cols="50" id="message" class="required" placeholder="Message"></textarea>
    </li> <!-- END input-name -->
    </ul> <!-- END #contact -->
    <button type="submit" class="btn btn-primary btn-lg pull-right">Send Message</button>
</form> 
chiwangc
  • 3,428
  • 16
  • 23
  • 31

3 Answers3

1

if you are not using ajax then write php file name in form action attribute currently there is #. then you php file will be called.

Manish Shukla
  • 1,305
  • 2
  • 8
  • 21
1

Change the below code

<form action="#" id="contact-form">

to

<form action="mailer.php" method="post" id="contact-form">

hope this will help.

Jithin Varghese
  • 1,494
  • 2
  • 20
  • 45
  • My old .php for my old website looked like this was called "mailer.php" so I should change "name" to "mailer yes? –  Apr 16 '15 at 07:15
  • yes that's right...check my edited answer...If it works please vote my answer. – Jithin Varghese Apr 16 '15 at 07:16
  • I think it's my .php file that is the issue as the form isn't working still! I can't post my .php contents as it won't let me, how can I get around this? –  Apr 16 '15 at 07:28
  • @JackEvans :- use method="post" inside form...check my edited answer again. – Jithin Varghese Apr 16 '15 at 07:32
0

You have to include the in action="#" the php file. example: action="contactForm.php". That's how the HTML code knows where to send the parameters.

Also, make sure your server supports the 'mail' function.

AND!

I have a good standard example for you of a well written mailing php file that I used. So you can check yourself for syntax issues.

<?php 
require_once "Mail.php";

        if(isset($_POST['email'])) {

            $email = $_POST['email'];       //this is how you get your variables from the HTML file. 'edit' is the id of the element. 
            $email_to = "yourEmail@example.com";

            $host = "ssl://smtp.gmail.com:465";  //use your email host - this example is gmail based. (you can search for your own email host via google). 
            $username = 'username@example.pro';
            $password = 'yourPass';

            $email_subject = "You have a new email from $email via example.com website";
            $message = $_POST['text']; 

            $headers = array ('From' => $email, 'To' => $email_to,'Subject' => $email_subject);
            $smtp = Mail::factory('smtp',
              array ('host' => $host,
                'auth' => true,
                'username' => $username,
                'password' => $password));

            $mail = $smtp->send($email_to, $headers, $message);

            if (PEAR::isError($mail)) {
              echo($mail->getMessage());
            } else {
              echo("Message successfully sent!\n");
            }

        }

In case of sending emails with ajax - it's an other thing.. and I can help you with that too.

W.Doch
  • 3,983
  • 9
  • 58
  • 117