I have a big form, I serialize
all the data and send them to a PHP page to then send them by e-mail.
My Question is:
How can I send the email all the data without calling it one by one?
I call just a few data, like name, email, but all the others data I would like to add automatically inside the email.
This is my code:
var data = $("#FormWorkspace").serialize();
//chiamata ajax
$.ajax({
type: "POST",
url: "form-engine.php",
data: data,
dataType: "html",
success: function()
{
alert("success" + data);
},
error: function()
{
alert("no success " + data);
}
});
and the PHP is:
session_start();
$nome = urldecode($_POST['nome']);
$email = urldecode($_POST['email']);
$phone = urldecode($_POST['phone']);
$company = urldecode($_POST['company']);
$nation = urldecode($_POST['nation']);
$messaggio = urldecode($_POST['messaggio']);
$myPostVar = array();
parse_str($_POST['data'], $myPostVar);
//Send mail
$to = $tua_email;
$sbj = "Richiesta Informazioni - $sito_internet";
$msg = "
<html>
<head>
<style type='text/css'>
body{
font-family:'Lucida Grande', Arial;
color:#333;
font-size:15px;
}
</style>
</head>
<body>
<h1>Richiesta Preventivo</h1>
<br />
<h2>Dati udente</h2>
<p>Nome: $nome</p>
<p>Email: $email</p>
<p>Phone: $phone</p>
<p>Company: $company</p>
<p>Paese: $nation</p>
<h3>Messaggio</h3>
<p>$messaggio</p>
<h3>Prodotti selezionati</h3>
$myPostVar // How I can write here??
<p>Fine</p>
</body>
</html>
";
$from = $email;
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$headers .= "From: $from";
mail($to,$sbj,$msg,$headers); //Invio mail principale.