I've tried using PhpMailer to test if I can send emails properly. At first I've tried this in my pc using localhost and it worked fine, but when I uploaded my code on a live server I was getting an "Internal Server Error" pointing to some line in the jquery.min.js file from the developer tools in chrome. Also the way the site gets the form information is via jquery then passes them to the php file assigned to the form's "action" attribute. Here is my code. filename is "contacttest.ph"
<?php
require 'PhpMailer/PHPMailerAutoload.php';
$name = $_POST['name'];
$email = $_POST["email"];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = '******.******@gmail.com';
$mail->Password = '*******';
$mail->AddReplyTo('******.******@gmail.com');
$mail->AddAddress('*********@gmail.com');
$mail->SetFrom('*****.*******@gmail.com');
$mail->Subject = $_POST['subject'];
$mail->Body = "You have been contacted by $name with regards to $subject, their additional message is as follows." . PHP_EOL . PHP_EOL . "\"$comments\"" . PHP_EOL . PHP_EOL . "You can contact $name via email $email, or via phone $phone";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}else{
echo "<fieldset class='alert alert-success'>";
echo "<div id='message'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
}
?>
And this is the javascript that processes the form info
$('#contactform').submit(function () {
var action = $(this).attr('action');
$("#message").slideUp(750, function () {
$('#message').hide();
$('#submit')
.after('<img src="images/loader.gif" class="loader" />')
.attr('disabled', 'disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
subject: $('#subject').val(),
comments: $('#comments').val(),
//verify: $('#verify').val()
},
function (data) {
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform').fadeOut('slow', function () {
$(this).remove()
});
$('#submit').removeAttr('disabled');
if (data.match('success') != null) $('#contactform').slideUp('slow');
}
);
});
return false;
});
as well as the form itself
<form method="post" action="contacttest.php" name="contactform" id="contactform">
<div class="col-sm-12">
</div>
<div class="col-sm-12 p-top-40">
<fieldset>
<label for="name" accesskey="U">
<span class="required">*</span>Your Name</label>
<input class="form-control" name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E">
<span class="required">*</span>Email</label>
<input class="form-control" name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone" accesskey="P">
<span class="required">*</span>Phone</label>
<input class="form-control" name="phone" type="text" id="phone" size="30" value="" />
<br />
</fieldset>
</div>
<div class="col-sm-12 p-top-40">
<fieldset>
<label for="subject" accesskey="S">Subject</label>
<select class="form-control" name="subject" id="subject">
<option value="Support">Support</option>
<option value="a Sale">Sales</option>
<option value="a Bug fix">Report a bug</option>
</select>
<br />
<label for="comments" accesskey="C">
<span class="required">*</span>Your comments</label>
<textarea class="form-control margin-bottom-15" name="comments" cols="40" rows="5" id="comments"></textarea>
<button type="submit" class="btn btn-info btn-lg btn-fill" id="submit" value="Submit">Send Message</button>
</fieldset>
</div>
</form>
Thanks and if you need more information i'll try to get them.