Php联系表格路径还是?

I am using Joomla 3 and i creat a simple php form and it is working on a simple html page but when i tried to use it with joomla didnt do anything I am using it on FTP server not local both cases

i tried with <?php include(' component.php'); ?> but same i have no idea what to do i am not pro with php , joomla please help

component.php file

defined('_JEXEC') or die;

$errors = '';
$myemail = 'hety@gmail.com';//<---- email address .
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['text']))
{
    $errors .= "
 Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$password = $_POST['text']; 
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "
 Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. /n ".
    " Here are the details:
 Name: $name 
 Email: $email_address 
 Text: $text 
"; 

    $headers = "From: $myemail
"; 
    $headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: index.php');
} 
?>
<!DOCTYPE html> 
<html>
<head>
    <title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>

index.php file

<form method="POST" name="contactform" action="templates/oniongraphicscomponent.php"> 
<p style="color:#FBFF94"> Character Name </p>
<input class="form-field" type="text" name="name" required/>
<input class="form-field"  type="text" name="text" required />
<div class="form-title"><p style="color:#FBFF94"> Email </p></div>
<input class="form-field" type="text" name="email"required /><br><br>
<div class="submit">
<input class="submit" type="submit" value="Submit" />
</div>
</form>

i have different file called component and <?php include('component.php'); that file into index.php where my form is full path is 'htdocs/templates/mytemplate/component.php'