Balagosh Balagosh - 1 month ago 14
PHP Question

linking contact form to an email HTML/PHP

I'm trying to make the Contact us form working,

P.S. I'm not a Developer, my coding skills is very limited.

this is the HTML code: (from a template with some adjustments)



<!--Contact Starts -->
<div class="container contactform center">
<h2 class="text-center wowload fadeInUp">Get in touch</h2>
<div class="row wowload fadeInLeftBig">
<div class="col-sm-6 col-sm-offset-3 col-xs-12">
<input type="text" placeholder="Name">
<input type="text" placeholder="Company">
<input type="text" placeholder="Email">
<input type="text" placeholder="Subject">
<textarea rows="5" placeholder="Message"></textarea>
<button class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>

</div>
</div>





and this is the PHP script: (wrote it myself)



$name = $_POST['Name'] ;
$from = $_POST['Email'] ;
$message = $_POST['Message'] ;
$to = "contact@mywebsite.com" ;
$subject = "Website Contact Form" ;

mail ($to, $subject, $message, "From: " . $name . $company . $email) ;
echo "Your Message Has Been Sent" ;





I'm not sure what I did wrong, but it's not workign.

the php file called emailscript.php located at /assets/php/emailscript.php

right now I'm getting an error this error: "Not Found

The requested document was not found on this server."

Answer

Encircle your code in isset function to avoid any error

<?php
if(isset($_POST['Name']))
{

    $name=$_POST['Name'] ;
    $from=$_POST['Email'] ;
    $message=$_POST['Message'] ;
    $to="contact@mywebsite.com" ;
    $subject="Website Contact Form" ;

    mail ($to, $subject, $message, "From: " . $name . $company . $email) ;
    // it echo not eco
    echo "Your Message Has Been Sent" ;

}
?>