Hi I'm new to php and swift mailer and I face this problem when I want to send the data from a bootstrap form. When I use a bootstrap form I get an empty mail, but when I use a simple html form I get a .txt file with the information from the form in the mail. Here's my index.php code:
<form id="main-contact-form" name="contact-form" method="post" action="contact_email.php" role="form">
<div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject" required="required">
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required="required"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn-submit">Send</button>
</div>
</form>
and here's my contact_email.php code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
$mesage = filter_var($_POST['messsage'], FILTER_SANITIZE_STRING);
$data = 'Name: '.$name.'<br />
Subject: '.$subject.'<br />
Email: '.$email.'<br />
Message: '.$mesage;
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('myemail@gmail.com')
->setPassword('********');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Email From My Website')
->setFrom(array('myemail@gmail.com' => 'website'))
->setTo(array('myemail@gmail.com'))
->setBody($data, text/html);
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
?>
</body>
</html>
please tell me why I'm getting an empty mail and how to fix it and why I'm getting the information in a .txt file. thank you in advance :)