开发者

php sending email

开发者 https://www.devze.com 2023-01-13 08:06 出处:网络
mailer.php <?php if(isset($_POST[\'submit\'])) { $to = \"abc@gmail.com\"; $subject = \"Contact via website\";

mailer.php

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

$to = "abc@gmail.com";
$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?


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.


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("youraccount@example.com","test","works"); <br>
?>

Run it and check your e-mail.

0

精彩评论

暂无评论...
验证码 换一张
取 消