0

So everytime I submit my form it just shows my php code, i've tried looking in other threads but i didnt find an answer to my question, here's my html code

<form action="contactus.php" method="post">
<div  class="form-group">
    <label for="Subject">Subject*</label>
    <input name="subject" class="form-control" id="subject1" placeholder="Subject">
</div>
<label for="sabject">Why do you want to contact us?</label>
    <br>
    <select name="select">

        <option value="General Inquiry">General Inquiry</option>
        <option value="hampion Guide Request">Champion Guide Request</option>
        <option value="League of Legends Show(s) Request">League of Legends Show(s) Request</option>
        <option value="Podcast - League of Legends">Podcast - League of Legends</option>
    </select>
    <label for="fname">First Name*</label>
    <input type="text" name="firstname" class="form-control" id="namef" placeholder="First Name">

    <label for="lname">Last Name</label>
    <input type="text" name="lastname" class="form-control" id="namel" placeholder="Last Name">
    <label for="email_adress">Email Adress*</label>
    <input type="email" name="email_adress" class="form-control" id="email_adress" placeholder="Email Adress">
    <label for="message">Message*</label>
    <input name="message2" class="form-control" id="message" placeholder="message">
    <input style="margin-top: 50px;" value="Send Form" name="submit" type="submit">Submit</button>
</form>

and here's my php code

<?php
$to ="sudaiguy1@gmail.com";
$from = $_POST['email_adress'];
$email_subject = $_POST['subject'];
$subject = "your subject here"
$message = $_POST['select'];
$message2 = $_POST['message2'];
$name = $_POST['firstname'];
if (empty($name)||empty($from))
{
    echo "Name and email are mandatory!";
    exit;
}
elseif (empty($email_subject)||empty($message)) {
    echo "Your email or subject are blank, please write something in them";
    exit;
}
elseif (empty($name)||empty($message2)) {
    echo "Your name or message are empty";
    exit;
}
$name2 = $_POST['lastname'];
$email_from = "sudaiguy1@gmail.com";
$email_body = $_POST['You have been contacted by $name $name2 and his email is $from. \n The message he wanted to say was in the subject of $message and the message is $message2'];
$headers = "From: $email_body"
mail($to,$email_subject,$email_body,$headers);
if($sent) {
    print ("You have successfully submitted it."); 
}
else {
    print ("We have encountered an error sending your message, please try again.");
}
?>

I have tried multiple things, tell me if u need some more information

guy
  • 7
  • 4
  • 3
    Are you sure you have web-server? – u_mulder Nov 29 '16 at 19:21
  • what is the name of the file with your php in it? does it have a .php extension? – WEBjuju Nov 29 '16 at 19:23
  • Not that it is used elsewhere but there is a missing semi-colon after `$subject = "your subject here"` and `$email_body = $_POST['You have been contacted by $name $name2 and his email is $from........` is just plain nonsense - also, `$headers = "From: $email_body"` missing semi-colon – Professor Abronsius Nov 29 '16 at 19:34
  • oh I need a webserver? I'm running it in my local pc, how do I get a webserver? – guy Nov 29 '16 at 19:38
  • @guy, In my experience most beginners products like XAMPP (Windows) or MAMP (Mac OSX) which have a webserver/PHP setup right out of the box. On Linux you'd install *apache* and PHP via the distro's package manager. – HPierce Nov 30 '16 at 01:30
  • I saw $email_body on a video, probably outdated, what I do instead, how do I send the email's content. – guy Nov 30 '16 at 05:58

0 Answers0