coure2011
coure2011

Reputation: 42514

php sending email

mailer.php

<?php
if(isset($_POST['submit'])) {

$to = "[email protected]";
$subject = "Contact via website";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "1";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {
echo "0";
}
?>

jquery code

$('.submit').click(function(){
            $('span.msg').css({'visibility': 'visible'}).text('Sending...');
            $.post("mailer.php", $(".contactPage").serialize(),
                function(data){
                    $('span.msg').text((data == "1") ? 'Your Message has been received. Thank you' : "Could not send your message at this time").show();
                });

            return false;    
        });

I am always getting

Could not send your message at this time

I have almost no knowledge in php, whats i am doing wrong?

Upvotes: 0

Views: 175

Answers (2)

ern0
ern0

Reputation: 3172

First of all, check server's mail settings. If your script resides on a server, which you don't administer, the simplest way is to do this is creating a simple PHP file with the following content:

<?php 
  mail("[email protected]","test","works"); <br>
?>

Run it and check your e-mail.

Upvotes: 0

VolkerK
VolkerK

Reputation: 96189

Your php script never prints just 1 it prints 0 or 1Data has been submitted to... thus (data == "1") can never be true.


btw: Your script could at least use the return value of mail() to decide whether it signals success or failure.

Upvotes: 5

Related Questions