i have a form with inputs for name and mail. The Code looks like this:
<form role="form" method="post" action="email.php">
<input type="text" class="sendmail" name="name" placeholder="Your name" />
<input type="text" class="sendmail" name="email" placeholder="Your email" />
</form>
Additionally i need to pass some div content (.inner) to the .php mailer. Code looks like this:
$(function() {
$('.send').click(function(e) {
$.ajax({
url: 'email.php',
type: 'POST',
data: {'message': $('.inner').html()},
success: function (data) {
alert('You data has been successfully e-mailed');
}
});
});
});
The .php mailer:
$email = $_POST['email'];
$subject = "Subject";
$name = $_POST['name'];
$content = $_POST['message'];
$to = 'my@email.com';
$test = '
<html>
<head>
<title>Email: '. $email .'</title>
</head>
<body>
<p>Von: '. $name .'</p>
<div>
'. $content .'
</div>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=utf-8' . "
";
$headers .= "From: $email
";
mail($to, $subject, $test, $headers);
After submitting i'll get an email with only the ajax script submitted $_POST['message'];
.. $email
and $name
wont show, not in the $test
area nor will the email be displayed in the mail header. My guess is that the ajax script overrides the "normal" form submit? For some help and insights i would be grateful.