Hi friends, I am new PHP. in this I want to send an email from my Static page which has some text fields and the user has to fill all the fields and then on clicking the submit button it has to send email to my email address(yahoo mail address)
I have done this but I am un able to send from Firefox but I am able to send from chrome and at the same time my page is re directing to PHP page which is not supposed to do that. here is the my code. Please find the bug in that and tell me the correct answer
<input name="name" type="text" id="name" value="" />
<input name="email" type="text" id="email" value="" />
<input name="website" type="text" id="loc" value="" />
<input name="subject" type="text" id="phone" value="" />
<textarea name="message" rows="20" cols="50" id="message" ></textarea>
<input type="submit" value="Submit" class="button" onClick="validate();">
<input type="reset" value="Reset" class="button">
var fname,phone,email,message,loc;
function validate()
{
fname=document.getElementById('name').value;// alert(fname);
loc=document.getElementById('loc').value;//alert(loc);
phone=document.getElementById('phone').value;//alert(phone);
email=document.getElementById('email').value;//alert(email);
message=document.getElementById('message').value;//alert(message);
if(notEmpty(fname,'Please Enter First Name') && notEmpty(loc,'Please Enter location') && notEmpty(message,'Please Enter Your Message'))
{
if(email!="")
{
if(emailValidator(email,'please Enter Valid MailId'));
}
//document.form1.submit();
document.getElementById('conmsg').innerHTML="Processing....Please Wait..!";
contactUs();
}
}
function contactUs()
{
var xml = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xml=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xml=new ActiveXObject("Microsoft.XMLHTTP");
}
xml.onreadystatechange=function()
{
if (xml.readyState==4 && xml.status==200)
{ //alert(xml.responseText);
document.getElementById('conmsg').innerHTML = xml.responseText;
document.getElementById('name').value='';
document.getElementById('loc').value='';
document.getElementById('phone').value='';
document.getElementById('email').value='';
document.getElementById('message').value='';
}
}
var con= fname+":"+phone+":"+email+":"+message+":"+loc;
xml.open("GET","putcontact.php?convar="+con,true);
xml.send();
}
///////////////GetXmlHttpObject/////////////
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
and my PHP code is below
<?php
if($_GET['convar']!="")
{
$varbles=explode(":",$_GET['convar']);
$fname=$varbles[0];
$phone=$varbles[1];
$email=$varbles[2];
$message=$varbles[3];
$loc=$varbles[4];
$mail_text= "Name:".$fname." \r\n Location: ".$loc." \r\n Mobile:".$phone." \r\n Email:".$email." \r\n Message:".$message."\r\n ";
$to="ganeshxxxxxxx@yahoo.xxxxx";
$to2="phaxxxxx@gmail.xxxx";
$headers = "From: ganeshxxxxx@yahoo.xxx" . "\r\n" .
"Reply-To:ganeshxxxxxx@yahoo.xxx" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$subject = "Feed Back From Website:";
$message =$mail_text;
if(mail($to, $subject, $mail_text, $headers))
{
echo '<font color="#660000">Your message has been sent. Thank you for your Feed back.</font>';
}
else
{
echo '<font color="#660000">There was an error in sending email!</font>';
}
}
?>
Please tell me where I am wrong.