0

Allright, so I am pretty new to PHP so I thought I would ask you guys what I am doing wrong. I am currently developing a website were you can contact the company through this e-mail form.

However, for some reason the email won't be delivered. I have tried multiple e-mails (and played a little with the code) and it just won't work.

Here is the mail.php script:

    <?php
if ($_POST) {
    $name  = $_POST['name'];
    $email = $_POST['email'];
    $text  = $_POST['text'];

    //send email   
    mail("myemail@gmail.com", "email enquiry", $text, "From:" . $email);
}

?>

Here is the snippet about the form from my script.js:

    //Contact Form Code:
        $(function (e) {
            $(".form-button").click(function (e) {
                var $error = 0;
                var name = $("#form-name").val();
                var email = $("#form-email").val();
                var text = $("#form-msg").val();
                var security = $("#form-security").val();


                if(name == "" || email=="" || text=="" ){
                    $('#details-error-wrap').fadeIn(1000);
                    $error = 1;

                }else{
                    $('#details-error-wrap').fadeOut(1000);
                }

                if(security != 8 ){
                    $('#security-error-wrap').fadeIn(1000);
                    $error = 1;

                }else{
                    $('#security-error-wrap').fadeOut(1000);
                }

                if( /(.+)@(.+){2,}\.(.+){2,}/.test(email) ){

                } else {
                  $('#details-error-wrap').fadeIn(1000);
                  $error = 1;
                }



                var dataString = 'name=' + name + '&email=' + email +   '&text=' + text;

                if($error == 0){
                    $.ajax({
                        type: "POST",
                        url: "mail.php",
                        data: dataString,
                        success: function () {
                            $('#details-error-wrap').fadeOut(1000);
                            $('#security-error-wrap').fadeOut(1000);
                            $('#form-sent').fadeIn(1000);
                        }
                    });
                    return false;
                }

                e.preventDefault();
            });
        });


});

And lastly, here is the HTML:

        <div class="seven columns">

        <div id="form-sent" class="hide">   
            <div class="alert-box success">Message sent: Thankyou for your enquiry</div>
        </div>
        <form id="contact-form">
            <label>Name *</label>     
            <input id="form-name" type="text"/>
            <label>Email *</label>
            <input id="form-email"  type="text" />
            <label>Message *</label>
            <textarea id="form-msg"></textarea>
            <div id="details-error-wrap"  class="hide"> 
            <div class="alert-box alert error-box">Error: Please ensure all fields are filled in correctly</div>
            </div>
            <label>Security Question *</label>
            <input id="form-security" type="text" placeholder="7 + 1 = ?" />
            <div id="security-error-wrap"  class="hide">    
                <div class="alert-box alert error-box">Error: Security question is incorrect</div>
            </div>  
            <input type="submit" value="Submit" class="form-button right" />

        </form>

    </div>
</div>

I posted all three related things. Parts of this website is from a template I'm using, so if you think the problem is in a different file just let me know.

Thanks in advance, I hope someone is able to help me :)

4

1 回答 1

0

Firstly, it might be ending up in your SPAM folder.

Are you sending the email using your personal email address? Such as me@gmail.com?

If so, that's obviously not going to work, you need to setup SMTP in order for the emails to get passed the firewalls and to actually make it to the inbox.

Might want to format your script better, also, use an IF statement to see if the email is actually being sent by the PHP:

 $to = 'myemail@gmail.com'; //Change this to the email you're using
 $subject = 'Website Contact Form';
 $headers = "From: " . "Me!! <myemail@gmail.com>" . "\r\n"; //This too
 $content  = "Hey!";

 if (mail($to, $subject, $content, $headers)) {
  echo "Success! Email was sent - Yay!";
 } else {
  echo "Error sending Email! booo!";
 }
于 2013-09-06T14:28:11.070 回答