If my php code is appearing in the URL after I submit the form, why is it not forwarding the information to my email address?

时间:2019-04-16 23:05:42

标签: php

I'm relatively new to using php so pardon my incompetence. I am currently working on a project where I need a contact form. I am having issues of the browser not parsing the php (It's what I assume is the issue). Is there an issue in my code (possibly file extensions) or the web hosting service I am using (HostGator)? Any help would be greatly appreciated!

I've tried renaming the file extensions to php and creating an ht access file to solve the problem (of which I can't seem to pinpoint).

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTPS_HOST}%{REQUEST_URI} [L,R=301,NE] 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]



<?php

if (isset($_POST['submit'])) {
    $name = $_POST['full-name'];
    $company = $_POST['company-name'];
    $phone = $_POST['phone-number'];
    $mailFrom = $_POST['email'];
    $needs = $_POST['your-needs'];
    $message = $_POST['your-notes'];


    $mailTo = '123@emailaddress.com';
    $headers = 'From: {$mailFrom}';
    $txt = 'You have received an email from '.$name.'.\n\n'.$message;


    mail($mailTo, $company, $txt, $headers, $phone, $needs);
    header('Location: index.html?mailsend');
    echo "Email sent!";
}

Below is what I have in a file called "contact" of which I changed the extension from html to php.

<form action="contactform.php" method="POST">

I'd expect to at least get an email when I submit the form, with a note saying "Email sent!". What I end up getting is a URL that has all the php code in it redirecting me to a 404 page error not found.

0 个答案:

没有答案