-3

I have some code with the mail() function. I don't know why its not want to send the email, but when i click on the mail button it makes "Din bedsked er nu sendt" and if we translate it, it will be "Your messages has been sent" But when i check my mail there will not come anything.

<?php
if (isset($_POST['navn']) && isset($_POST['besked']))
{
    if (empty($_POST['navn']))
    {
        echo "Du skal indtaste dit navn"; 
    }
    elseif (empty($_POST['besked']))
    {
        echo "Du skal indtaste en besked";
    }
    else
    {
        $modtager = "pressweb10@gmail.com";
        $emne = "" .$_POST['emne']. "\n";
        $besked = "Hej, du har modtaget mail fra en bruger: \n 
        Navn: " .$_POST['navn']. "\n
    Emne: " .$_POST['emne']. "\n
        Besked: " .$_POST['besked'];
        $header = "from:".$_POST['mail']."/n";

        mail($modtager, $emne, $besked, $header);
        echo "Emailen er nu sendt!";
    }
}
?>

<form action="hey.php" method="post">
    Navn: <br>
    <input type="text" name="navn" style="width: 200px;"> <br><br>

    Mail: <br>
    <input type="text" name="mail" style="width: 200px;"> <br><br>

    Emne: <br>
    <input type="text" name="emne" style="width: 200px;"> <br><br>

    Besked: <br>
    <textarea name="besked" style="width: 200px; height: 100px;"></textarea> <br><br>

    <input type="submit" value="Send mail">
</form>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

0

First check the return value of the mail() function. From the PHP docs

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

mail() is not very reliable. Most people use either PHPMailer or SwiftMailer. You can find more information on them on their websites.

Community
  • 1
  • 1
Markus Müller
  • 2,611
  • 1
  • 17
  • 25