0

I been working on a personal website for a while now and I am just a beginner. I am currently using Bulma.io framework for css along with javascript. My current issue is that when I try running the php script (Making a contact Form) instead of sending email it just downloads the php source code. Can someone look at what is wrong? I looked at couple forums and they said host it and I host it on Firebase which doesn't make a difference. This is the php code

<?php

$name =$_REQUEST['name'];
$email =$_REQUEST['email'];
$msg =$_REQUEST['Message'];

$to = 'myemail@gmail.com';
$subject = 'Form Submission';
$message = "Name: " .$name. "\n". "email: " .$email. "\n". "Message: " .$msg;
$headers= "From: " .$email;

if (empty($name) || empty($email) || empty($msg))
{
    echo "Please fill all the fields";
}
else
{
    if(mail($to,$subject,$message,$headers))
    {
        echo "<h1> Sent Sucessfully! Thank you"." ".$name.", I will contact you shortly";
    }

}


?>

This is my HTML

<form class ="Contactform" action = "contact.php">
        <div class = "columns">
            <div class = "column is-half">
                <div class = "title is-1 ">
                    Contact Form
                </div>
            </div>
                <div class = "column is-half">
                    <div class = "field">
                        <label class = "label namepart">Name</label>
                        <div class = "control">
                          <input class ="input name" type="text" placeholder = "e.g John Doe" name = "name"> 
                        <div class="field emailpart">
                            <label class="label">Email</label>
                            <div class="control has-icons-left has-icons-right">
                             <input class="input email" type="email" placeholder="Email input" value="name@" name = "email">
                             <span class="icon is-small is-left">
                                <i class="fas fa-envelope"></i>
                             </span>
                             <span class="icon is-small is-right">
                              </span>
                            </div>
                        </div>
                     </div>
                        <div class ="Messagepart">
                     <label class = "label">Message</label>
                        <textarea class="textarea" placeholder="e.g. Description" name = "msg"></textarea>
                    </div>
                    <div>
                        <br>
                        <button class= "button is-sucess "> Submit </button>
                    </div>
                </div>
            </form>


  • Does this answer your question? [Simple PHP contact form with Firebase hosting](https://stackoverflow.com/questions/35523819/simple-php-contact-form-with-firebase-hosting) – Holden Rohrer May 26 '20 at 00:45
  • Sadly, no. I think I already saw the that forum. It just confirm my thought that Firebase doesn't support php. However, I still can't figure a way to test whether or not my thing works. I just assumed that this problem is simple enough where people can tell either my php isn't setup right with my html or I just can't host a web haha. – Anthony G May 26 '20 at 00:56
  • You can try running apache locally to test it if you don't want to bother with finding a host. I may have misread the question, but is there a problem other than the php file downloading? (which would be because firebase only hosts static files, I think) – Holden Rohrer May 26 '20 at 01:07
  • @HoldenRohrer I am not sure what you mean by running apache locally. I am on a mac if that makes a difference. I used live server vscode to see my webpage. The current issue I have is the fact that whenever I push submit instead of sending email it just ask where I would download the php source code file. Thanks for the quick response though. I am still inexperience. – Anthony G May 26 '20 at 01:17
  • To use PHP in a webpage, you need to run it through a webserver. VS Code has a PHP server (addon?) extension in its store that you can try, or you can run Apache. I think the following guide can help with the latter on macOS: https://websitebeaver.com/set-up-localhost-on-macos-high-sierra-apache-mysql-and-php-7-with-sslhttps (probably ignore the mySQL bits) – Holden Rohrer May 26 '20 at 01:29
  • @HoldenRohrer Ah, Thanks! Couple more questions if you are able to answer them. I was able to see my php script in action. Since I am not experience is it suppose to open an empty window when I do echo? Could I just add an echo javascript where it can just give the user an alert on top instead of opening a new page? – Anthony G May 26 '20 at 01:45

0 Answers0