I made a PHP website (index.php) with the following code:
$message=
'Full Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
Message: '.$_POST['comments'].'<br />
Current Website: '.$_POST['website'].'<br />
Business Name: '.$_POST['business'].'<br />
';
require "phpmailer/class.phpmailer.php"; //include phpmailer class
include "phpmailer/class.smtp.php";
$self = $_SERVER['SCRIPT_NAME'];
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->Host = localhost;
//Set who the message is to be sent from
$mail->setFrom('coherenthub@gmail.com', 'Coherent');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('coherenthub@gmail.com', 'Coherent');
//Set the subject line
$mail->Subject = 'Contact Form';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->MsgHTML($message);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
die("There was an error sending the email.");
} else {
die("true");
}
and it worked on the GoDaddy website. But, when I introduced AJAX into the website with the following:
<script>
var ajax = {
isSubmiting: false,
send: function() {
if(ajax.isSubmiting == false) {
ajax.isSubmiting = true;
var userName = $("input[name=name]").val();
var userEmail = $("input[name=email]").val();
var userComments = $("textarea").val();
var currentBusiness = $("input[name=business").val();
var currentWebsite = $("input[name=website]").val();
ajax.SetText("Sending...");
$.post("sendmail.php", {
name: userName, email: userEmail, comments: userComments, business: currentBusiness, website: currentWebsite
}, function(data) {
if(data == "true") {
ajax.SetText("Sent!");
$.get("sent.html", function(sentData){
$("#content").html(sentData);
});
} else {
ajax.SetText("Send mail");
$.get("unsent.html", function(sentData){
$("#content").html(sentData);
});
}
ajax.isSubmiting = false;
});
}
else alert("You can only send 1 email at a time");
},
SetText: function(text) {
$("input[type=button]").val(text);
}
}
</script>
This worked great with local server (although it was through a SMTP server through local) and the previous PHP website worked with the $mail->Host = localhost;
but when I put it in a seperate file and linked it with AJAX and uploaded to GoDaddy, it kept sending errors.
I'm confident that the PHPMailer script is fine as it has worked before but for some reason it works on localhost under a gmail SMPT server but didnt work in GoDaddy with a localhost as it SHOULD'VE HAD.
Any suggestions?