While it is still somewhat unclear what your exact concern is, I have a few thoughts on your process.
1 - You are sending data to a php file as a string which is not recommended and is probably giving you problems right there. I have really seen 2 approaches to sending data to the server via post: A) store your data in a form and use jQuery's $().serialize() function, or B) store your data in a JSON object and send it that way.
Option B is my preferred method because JSON simplifies everything. It has the advantage that your data is already stored as key/value pairs, and PHP makes it super easy to work with JSON using the json_decode function. Let's make a few changes to the existing code you have:
$(document).ready(function() {
$("#submit").click(function() {
var email = $("#email").val();
var name = $("#Name").val();
var subject = $("#Subject").val();
var text = $("#textarea").val();
var telephone = $("#tel").val();
var varData = {
"email" : email ,
"name" : name,
"subject" : subject,
"text" : text ,
"telephone" : telephone
} //This is your data in JSON form
console.log(varData);
$.ajax({
type: "POST",
url: 'sendPHP.php',
data: JSON.stringifiy(varData), //Notice that I added JSON.stringify
success: function() {
alert("message sent");
}
});
});
});
Now I'll show you how to handle this in PHP - it's actually very simple.
Step 1 - turn this JSON object into an associative array so that it's easy to work with:
$input = json_decode(file_get_contents('php://input'), true);
Now we have a variable called $input that is an associative array with all of your mail data - let's set up the variables you need.
$email = $input['email']; //Notice string in brackets is JSON key
$name = $input['name'];
$subject = $input['subject'];
$text = $input['text'];
$telephone = $input['telephone'];
Ok, cool - all of your data you gathered from the front end is now ready for use on the back end. So it looks like you're using the built-in mail() function that PHP offers. I would highly recommend using a library for this as they are typically much more reliable and verbose. My favorite is called PHPMailer - here's a link to their github page https://github.com/PHPMailer/PHPMailer.
If you'd like to use that library, the process is simple.
First, include the autoloader file in your script
<?php
require('PHPMailer-master/PHPMailerAutoload.php');
Next, and they have this documented in numerous examples, you create a new instance of PHPMailer and set some basic variables - this is straight from their documentation and I promise you'll have less headache than if you try the PHP mail() approach https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps.
Best of luck and let me know if I was unclear on anything.