Click here to Skip to main content
15,944,397 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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);
    if(notEmpty(fname,'Please Enter First Name') && notEmpty(loc,'Please Enter location') && notEmpty(message,'Please Enter Your Message'))
            if(emailValidator(email,'please Enter Valid MailId'));
    document.getElementById('conmsg').innerHTML="Processing....Please Wait..!";

function contactUs()
    var xml = null;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xml=new XMLHttpRequest();
    {// code for IE6, IE5
        xml=new ActiveXObject("Microsoft.XMLHTTP");
        if (xml.readyState==4 && xml.status==200)
        {    //alert(xml.responseText);
            document.getElementById('conmsg').innerHTML = xml.responseText;
    var con= fname+":"+phone+":"+email+":"+message+":"+loc;"GET","putcontact.php?convar="+con,true);
function GetXmlHttpObject()
    var xmlHttp=null;
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    catch (e)
        // Internet Explorer
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        catch (e)
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xmlHttp;

and my PHP code is below

    $mail_text= "Name:".$fname." \r\n Location: ".$loc." \r\n Mobile:".$phone." \r\n Email:".$email." \r\n Message:".$message."\r\n ";

            //$header='mailserver details';
            $headers =  "From:" . "\r\n" .
                        "" . "\r\n" .
                        "X-Mailer: PHP/" . phpversion();
            $subject = "Feed Back From Website:";
            $message =$mail_text;
                if(mail($to, $subject, $mail_text, $headers))
                {//we show the good guy only in one case and the bad one for the rest.
                    echo '<font color="#660000">Your message has been sent. Thank you for your Feed back.</font>';
                    echo '<font color="#660000">There was an error in sending email!</font>';


Please tell me where I am wrong.
Er. Tushar Srivastava 21-Sep-12 10:17am    
Notice the $to = "ganeshxxxxxxx@yahoo.xxxxx" ..... what are these x's for?
jim lahey 21-Sep-12 12:02pm    
It's just possible that the OP doesn't want the whole world knowing their real email address. Keyword: spam.
Er. Tushar Srivastava 21-Sep-12 12:04pm    
Oooooo......... And I didn't gave it a thought :-)

I'm too lazy to find a bug; after all, this is your problem.

But I can see one vulnerability, which is practically much worse than the bug. With the bug, you just fail to send a e-mail. But if you fix the bug, the vulnerability can be used to turn your computer into a zombie sending viruses or spam — in no time.

I explained it in my past answer. Please see:
unable to send mail , it showing the error in below code .[^].

Program safely,
Share this answer
The error is arising from javascript, not php. You can use Firefox Error Console to see the error. It will give you some details about it...
Additionally GetXmlHttpObject() function is unnecessary. You didn't need it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900