Dorwałem opcję w, której da się wywołać oddzielny plik w tym przypadku mail.php, w formularzu kontaktowym w html. I jest w nim zawarta treść, co i jak w kodzie php ma się dziać, poza plikiem z formularzem w html. Chodzi dokładnie o ten atrybut "action="mail.php".
<form class="form-area " id="myForm" action="mail.php" method="post" class="contact-form text-right">
<div class="row">
<div class="col-lg-6 form-group">
<input name="name" placeholder="Imię" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your name'" class="common-input mb-20 form-control" required="" type="text">
<input name="email" placeholder="Email adres" pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{1,63}$" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter email address'" class="common-input mb-20 form-control" required="" type="email">
<input name="subject" placeholder="Temat" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your subject'" class="common-input mb-20 form-control" required="" type="text">
</div>
<div class="col-lg-6 form-group">
<textarea class="common-textarea form-control" name="message" placeholder="Wiadomość" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Messege'" required=""></textarea>
</div>
<div class="col-lg-12">
<div class="alert-msg" style="text-align: left;"></div>
<button class="genric-btn primary circle" style="float: right;">Wyślij wiadomość</button>
</div>
</div>
</form>
Natomiast w tym pliku mail.php takie o to się kryją komendy:
<?php
$to = 'demo@site.com';
$firstname = $_POST["fname"];
$email= $_POST["email"];
$text= $_POST["message"];
$phone= $_POST["phone"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $email . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message ='<table style="width:100%">
<tr>
<td>'.$firstname.' '.$laststname.'</td>
</tr>
<tr><td>Email: '.$email.'</td></tr>
<tr><td>phone: '.$phone.'</td></tr>
<tr><td>Text: '.$text.'</td></tr>
</table>';
if (@mail($to, $email, $message, $headers))
{
echo 'The message has been sent.';
}else{
echo 'failed';
}
?>
Wyjaśniam tak dla potomnych!