Asked  9 Months ago    Answers:  5   Viewed   65 times

I am following a tutorial on how to implement a simple Bootstrap contact form with a PhP mailer script.

However when I click Send Message, my contact form downloads the PHP script rather than sending the email. What am I doing wrong?

Bootstrap - HTML

<form name="contactform" method="post" action="http://location_of_my_web_app/php/mailer.php" class="form-horizontal" role="form">

    <div class="form-group">
    <label for="inputName" class="col-lg-2 control-label">Name</label>
        <div class="col-lg-10">
        <input type="text" class="form-control" id="inputName" name="inputName" placeholder="Your Name">
    <div class="form-group">
    <label for="inputEmail1" class="col-lg-2 control-label">Email</label>
        <div class="col-lg-10">
        <input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Your Email">
    <div class="form-group">
    <label for="inputSubject" class="col-lg-2 control-label">Subject</label>
        <div class="col-lg-10">
        <input type="text" class="form-control" id="inputSubject" name="inputSubject" placeholder="Subject Message">
    <div class="form-group">
    <label for="inputPassword1" class="col-lg-2 control-label">Message</label>
        <div class="col-lg-10">
        <textarea class="form-control" rows="4" id="inputMessage" name="inputMessage" placeholder="Your message..."></textarea>

    <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
        <button type="submit" class="btn btn-primary">Send Message</button>


/* Set e-mail recipient */
$myemail = "";

/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$subject = check_input($_POST['inputSubject'], "Message Subject");
$message = check_input($_POST['inputMessage'], "Your Message");

/* If e-mail is not valid show error message */
if (!preg_match("/([w-]+@[w-]+.[w-]+)/", $email))
show_error("Invalid e-mail address");
/* Let's prepare the message for the e-mail */

$subject = "Someone has sent you a message";

$message = "

Someone has sent you a message using your contac form:

Name: $name
Email: $email
Subject: $subject



/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: http://location_of_my_thank_you_page/Static/contact_thankyou.html');

/* Functions we used */
function check_input($data, $problem='')
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
return $data;

function show_error($myError)

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>




"my contact form downloads the PHP script rather than sending the email"

It sounds like PHP is either not installed/running or not properly configured.

I suggest that you create a file called test.php file with <?php echo "Hello world"; ?> inside it and see if it does the same thing.

If it still wants to appear like it wants to download, then there's the problem; PHP is not installed or not properly configured and isn't parsing PHP as it normally should.

Create another file and place <?php phpinfo(); ?> and it should show you the server's information.

Wednesday, March 31, 2021
answered 9 Months ago

To send an email you need a SMTP server (local or remote). Actually your mail function just passes the mail to your SMTP server and is this one which really send your email.

In your php.ini appears this line

sendmail_path = /usr/sbin/sendmail -t -i

You should be aware if you use that configuration parameter (from manual):

If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.

But the most important thing here is you just uninstall sendmail so you can expect your mail goes nowhere. I know sendmail was giving you some problems, possibly configuration problems, but now your php.ini configuration is wrong.

How to solve it?

  • Start removing the sendmail_path parameter from the php.ini.

  • Install a simple to configure SMTP server like postfix.

  • Verify postfix is listening at port 22:

netstat -lnt

  • Try to send a mail from your php mail() function

  • Verify your mail has been sent correctly (check your /var/log/mail.log or /var/log/mail/mail.log files)

  • You also can verify the mail is not in the postfix queue:

postqueue -f

Wednesday, March 31, 2021
answered 9 Months ago

I've solved my own problem, here is a recap of the goal and what it took to accomplish.


  1. I wanted to use the bootstrap nav-tabs component for my navigation bar because I liked the look/feel of it better.
  2. I wanted to be able to set the 'active' class by parsing the incoming URI.
  3. I wanted sub-navigation to work as well.

New code based on first post:

<ul class="nav nav-tabs" id="supernav">
    <li id="page1"><a href="/page1.html"><i class="icon-home" style="margin-top:4px;"></i> Page 1</a></li>
    <li class="dropdown" id="page2">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Page 2 <b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li id="page2_home"><a href="/page2.html">Home</a></li>
            <li class="divider"></li>
            <li id="page2_2"><a href="/page2.2.html">Page 2.2</a></li>
            <li id="page2_3"><a href="/page2.3.html">Page 2.3</a></li>
    <li class="dropdown" id="page3">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Page 3 <b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li id="page3_home"><a href="/page3.html">Home</a></li>
            <li class="divider"></li>
            <li class="dropdown-submenu" id="page3_2">
                <a href="/page3.2.html">Page 3.2</a>
                <ul class="dropdown-menu">
                    <li id="page3_2_1"><a href="/page3.2.1.html">Page 3.2.1</a></li>
                    <li id="page3_2_2"><a href="/page3.2.2.html">Page 3.2.2</a></li>
    <li id="page4"><a href="/page4.html">Page 4</a></li>

Notice in the code above that there are no




set anywhere.

Because I wanted to make my nav on a static template which is used as a header for all templates I couldn't add any dynamically generated code based on incoming URI's but it turns out not to be necessary.

I added the following Javascript code to bottom of each template a visitor calls to help tell the nav-list which items to be marked as 'active'.

I used this script at the bottom of my /page1.html

<script type="text/javascript">
window.onload=function () {

To set /page3.2.2.html as the active page and all the nav lvls above it I did this

<script type="text/javascript">
window.onload=function () {

Now when a user comes to my site the nav gets loaded from a static file and the rest of the page contains the dynamic JavaScript that sets what components I want set active.

I also found it necessary to make this one little modification to my custom css in order to make sure no line appeared under my 'active' tab, just a visual thing probably needed because of my font settings.

.nav-tabs > li { margin-bottom: -3px; }

I would have posted some SS's but my 'rep' isn't above 10 yet, ha ha ha. Hopefully this helps someone else, god help us all when version 3 of bootstrap comes out and we have to figure this all out again. 8^)P

Wednesday, March 31, 2021
answered 9 Months ago

It's trying to upload a file to your local folder instead of tmp.

This should fix it:

Change $folder = '/tmp'; to $folder = '/tmp/';

Saturday, May 29, 2021
answered 7 Months ago

This editor you are using does not automatically insert content to your text_field, you have to do it yourself via javascript like this:


Generally this is a bad design and I recommend that you use other bootstrap wysiwyg editors like these,

  • bootstrap-wysiwyg
  • bootstrap-wysihtml5
  • Summernote

I personally use summernote in my projects.

Thursday, November 11, 2021
answered 3 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :