0

I am trying to make a contact form where a user can fill in the details and it will be sent to my email address. The PHP script says it is sent but when I check my email there is no mail. I am also trying to implement this using AJAX. This is my code

                        $('#submit').click(function () {
                                    var name = $('#name').val();
                                    var email = $('#email').val();
                                    var message = $('#message').val();

                                    $.ajax({
                                        type: 'POST',
                                        url: 'send.php?name=' + name,
                                        data: 'name=' + name + '&email=' + email + '&message=' + message,
                                        success: function (result) {
                                         //   $('#submit_wrp').load(location.href + ' #submit');
                                                $("#result").html(result);
                                           // $('#submit').val("Invited");
                                           // alert(name + " "  + email);

                                        },
                                        error: function (result) {
                                            alert("error" + name);
                                                $("#result").html(result);
                                        }
                                    });
                                });

This is the PHP code

$Rname = $_POST['name'];
$meesg = $_POST['message'];
$email = $_POST['email'];
$to = "example@gmail.com";
$subject = "Review";
$message = $meesg;
$headers = "From:" + $Rname + $email;
mail($to, $subject, $message, $headers);

  if (mail($to, $subject, $message, $headers)) {
    echo "Mail was sent and has done its job.";
} else {
    echo "Error, check your logs.";
}

Please help!!!!

Likitha
  • 51
  • 7

2 Answers2

0

hardcode your values then check again.

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

if there is problem then check your smtp settings on server.

Junaid
  • 592
  • 1
  • 7
  • 24
  • 2
    *"if there is problem then check your smtp settings on server."* - Thing is, that awful server they're on, doesn't offer SMTP to free accounts; *fact, not fiction*. – Funk Forty Niner Apr 05 '16 at 13:37
  • this link may helps [link](http://www.000webhost.com/forum/web-programming/23998-php-mail-function.html) – Junaid Apr 05 '16 at 13:44
  • @MJunaidAslam This link is very old. 000webhost has blocked the mail() function for so far I know this is because people made email bombs with it to spam other users e-mail accounts. – node_modules Apr 05 '16 at 13:50
  • I have output m variables and it prints it out. I checked on the SMTP settings. SMTP is localhost – Likitha Apr 05 '16 at 13:55
0

Did you search for the mail php possibilities at the forum of you hosting company? Try to look at the sendmail_path:

<?php
   phpinfo();  
?>

Maybe it is not configured properly.

Further maybe you need more headers to sent with your email to prevent filtering to the spambox.

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: frommail@gmail.com" . "\r\n" ."Reply-To: tomail@gmail.com". "\r\n" ."X-Mailer: PHP/" . phpversion();
jhofste
  • 36
  • 3
  • There is no need to use 'print' here. Simply including the phpinfo() function will output what you need. – mferly Apr 05 '16 at 13:39
  • I don't understand, what should I do with the phpinfo() function? – Likitha Apr 05 '16 at 13:45
  • Just remove 'print' and you're done: `` Voila! @Likitha - this was a comment on the post by @J. Hofste – mferly Apr 05 '16 at 13:46
  • Note that with or without `print` the `phpinfo()` will be executed anyways. – node_modules Apr 05 '16 at 13:48
  • with phpinfo() you can view your webserver configurations easily! – jhofste Apr 05 '16 at 14:01
  • I get this sendmail_from no value no value sendmail_path /usr/local/bin/phpsendmail /usr/local/bin/phpsendmail serialize_precision 100 100 short_open_tag On On SMTP localhost localhost smtp_port 25 – Likitha Apr 05 '16 at 14:03
  • I have even tried this, but there were no errors error_reporting(E_ALL); ini_set('display_errors', 1); – Likitha Apr 05 '16 at 14:04