Hi
i am working on contact form using SMTP. I am unable to send a mail. Please help me to fix the issue.
index.html
<div id="frmContact" class="w-form">
<div id="mail-status"></div>
<!-- <form action="contact.php" method="post">-->
<label for="name">Name:</label>
<input class="w-input" type="text" placeholder="Enter your name" id="cf_name" name="cf_name">
<label for="email"><p class="info">*</p>Email Address: <span id="cf_email-info" class="info"></span></label>
<input class="w-input" placeholder="Enter your email address" type="text" id="cf_email" name="cf_email">
<label for="email">Your Message:</label>
<textarea class="w-input message" placeholder="Enter your Message Here" id="cf_message" name="cf_message"></textarea><br>
<button name="submit" class="w-button" onClick="sendContact();">Send</button>
<!-- <input class="w-button" type="submit" value="Send">-->
<!--</form>-->
<div class="w-form-done">
<p>Thank you! Your submission has been received!</p>
</div>
<div class="w-form-fail">
<p>Oops! Something went wrong while submitting the form :(</p>
</div>
</div>
<script type="text/javascript">
function sendContact() {
var valid;
valid = validateContact();
if(valid) {
jQuery.ajax({
url: "contact.php",
data:'cf_name='+$("#cf_name").val()+'&cf_email='+
$("#cf_email").val()+'&cf_message='+
$("#cf_message").val(),
type: "POST",
success:function(data){
$("#mail-status").html(data);
},
error:function (){}
});
}
}
function validateContact() {
var valid = true;
$(".w-input").css('background-color','');
$(".info").html('');
if(!$("#cf_email").val()) {
$("#cf_email-info").html("(required)");
$("#cf_email").css('background-color','#FFFFDF');
valid = false;
}
if(!$("#cf_email").val().match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/)) {
$("#cf_email-info").html("(invalid)");
$("#cf_email").css('background-color','#FFFFDF');
valid = false;
}
return valid;
}
</script>
contact.php
<?php
require "classemail.php";
$mail = new EMail;
$mail->Username = 'webmaster@domainname.com';
$mail->Password = 'password';
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'contact@domainname.com';
$subject = 'Message from a contant - '.$field_name;
$mail->SetFrom("webmaster@domainname.com","Webmaster"); // Name is optional
$mail->AddTo($field_email,$field_name); // Name is optional
$mail->AddTo("contact@domainname.com","Webmaster");
$mail->Subject = $field_name . ' - From contact';
$mail->Message = "<div style='width:600px; margin:0px auto;'>
<div style='width:600px; height:auto; border-top:1px solid #dfdfdf; border-left:1px solid #dfdfdf; border-right:1px solid #dfdfdf; border-bottom:3px solid #da251e; float:left;'><img src='http://domainname.com/images/logo.png'></div><br>
<div style='width:560px; height:auto; border-left:1px solid #dfdfdf; border-right:1px solid #dfdfdf; padding:20px 20px; background-color:#f7f7f7; float:left;'>
<table width='450' border='0'>
<tr><td colspan=2><span style='font-family:Arial; font-size:12px; color:#2A4E98; font-weight:bold;'>Dear Sir / Madam</span></td></tr>
<tr><td align=left colspan=2><span style='font-family:Arial; font-size:12px; color:#000000;text-indent:40px;'></span></td></tr>
<tr><td align=left colspan=2> </td></tr>
<tr><td align=left colspan=2><b><u>My Contact Details :</u></b></td></tr>
<tr><td align=left width='280'> Contact Name : </td><td align=left width='280'>" .$field_name. "</td></tr>
<tr><td align=left> Email : </td><td align=left> " .$field_email. "</td></tr>
<tr><td align=left> Information Requested or Your Question: </td><td align=left> " .$field_message."</td></tr>
<tr><td align=left colspan=2> </td></tr>
<tr><td align=left colspan=2> </td></tr>
<tr><td align=left colspan=2>Thanks & Regards,</td></tr>
<tr><td align=left colspan=2> " .$field_name. "</td></tr>
</table></div>
<div style=' float:left; width:586px; height:30px; border-top:3px solid #da251e; background-color:#dfdfdf;border-left:1px solid #c5c5c5; border-right:1px solid #c5c5c5; border-bottom:1px solid #c5c5c5; float:left; line-height:30px; padding-left:15px; font-family:Arial; font-size:10px; color:#828282;'> Copyright ".date('Y')." Domain Name, Inc. All rights reserved.</div></div>" ;
//Optional stuff
//$mail->AddCc("ccaddress@example.com","CC Name"); // Set a CC if needed, name optional
$mail->ContentType = "text/html"; // Defaults to "text/plain; charset=iso-8859-1"
$mail->Headers['X-SomeHeader'] = 'abcde'; // Set some extra headers if required
$mail->ConnectTimeout = 30; // Socket connect timeout (sec)
$mail->ResponseTimeout = 8; // CMD response timeout (sec)
$success = $mail->Send();
if ($success)
{
print "<p class='success'>Thank you! Your submission has been received!</p>";
}
else
{
print "<p class='Error'>Oops! Something went wrong while submitting the form :(</p>";
}
?>