0

I have this code. It prints "Message sent successfully" but I have no message from my test from in my inbox.

Here is HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Basic Email Form</title>
    <style>
        * {
            margin:0;
            padding:0;
        }
        input, textarea {
            margin:10px;
            font-family:Arial, sans-serif;
            padding:10px;
        }
        input {
            width:280px;
            height:40px;
        }
        textarea {
            width:280px;
            height:120px;
        }
    </style>
</head>
<body>
    <form action="submit.php" method="post">
        <input type="text" name="name" placeholder="Name" /><br />
        <input type="text" name="from" placeholder="Email" /><br />
        <textarea placeholder="Message" name="message"></textarea><br />
        <input type="submit" value="Submit" />
    </form>
<body>
</html>

PHP file:

<?php
   $to = "prefertodie@gmail.com";
   $subject = "This is subject";
   $message = "This is simple text message.";
   $header = "From:".$_POST['from']." \r\n";
   $retval = mail ($to,$subject,$message,$header);
   if( $retval == true )  
   {
      echo "Message sent successfully...";
   }
   else
   {
      echo "Message could not be sent...";
   }
?>
Heart
  • 508
  • 1
  • 3
  • 14
  • possibly went to junk folder? – tonoslfx Aug 01 '13 at 13:57
  • 2
    You better check your mail server configuration, because just returning TRUE value form the mail() function doesn't ensure that mail has reached to the destination. – Kalpesh Patel Aug 01 '13 at 13:57
  • @kalpeshpatel you beat me to that heh! – Majo0od Aug 01 '13 at 13:57
  • @kalpeshpatel I don't know about server config. Can you tell the basic stuff to alter? – Heart Aug 01 '13 at 13:57
  • Well @Heart this link may help(not tried) http://stackoverflow.com/questions/14456673/sending-email-with-php-smtp-server – Kalpesh Patel Aug 01 '13 at 14:02
  • 1
    Check the mail logs on your server they will tell you if it went anywhere. – Anigel Aug 01 '13 at 14:03
  • @Fred, what are you trying to explain, because just creating variables without using it...how does that make sense? Please let me know if I am missing something. – Kalpesh Patel Aug 01 '13 at 14:19
  • @Fred, but why we need those variables? – Kalpesh Patel Aug 01 '13 at 14:23
  • Another probable cause that I have seen happen before, is the space before the `\r` in `$header = "From:".$_POST['from']." \r\n";`. Try removing it. – Funk Forty Niner Aug 01 '13 at 14:24
  • @kalpeshpatel What I think is happening, is that using `"From:".$_POST['from']."` may not be enough and that the **"from"** needs to first be defined as a variable, i.e.: `$from=$_POST['from'];` **above** `$to = "prefertodie@gmail.com";` I'm just trying to offer possible causes. – Funk Forty Niner Aug 01 '13 at 14:27
  • @Heart What I think may be happening, is that using `"From:".$_POST['from']."` may not be enough and that the **"from"** needs to first be defined as a variable, i.e.: `$from=$_POST['from'];` **above** `$to = "prefertodie@gmail.com";` I'm just trying to offer possible causes. Yet, what **Chinmay Sahu** made as an answer, makes sense. – Funk Forty Niner Aug 01 '13 at 14:33

3 Answers3

0

Check the spam folder, it usualy gets there when sending using the PHP mail()

I'd recommend you to use something like https://github.com/Synchro/PHPMailer for starters.

Then you could add smtp authentification and server setup(for example your gmail credentials), it's one of the safest way to be sure it's delivered and also to stay clear of the spam folder.

catalint
  • 1,895
  • 17
  • 17
0

As Kalpesh said, check the server configuration, this could be blocking the message. Also checking your junk/bulk folders is always a good idea, just in case.

James Williams
  • 678
  • 4
  • 14
0

I have check this code in my web server. It working fine. please check your server configuration.

Chinmay235
  • 3,236
  • 8
  • 62
  • 93