Search code examples
phpiishmail-server

How i can fix mail() function on PHP?


I use the Internet Information Services(IIS) with PHP. But the mail() function doesn't seem to be working. At first I tried to fix the php.ini. Then I downloaded hMailServer. Now it shows "Your message has been sent!" but I haven't got any messages in my inbox. I also checked the SPAM inbox. But I can't find anything.

<?php 

    error_reporting(-1);
    ini_set('display_errors', 'On');
    set_error_handler("var_dump");
    $name = $_POST['name'];
    $email = "[email protected]";
    $message = "Hello how are you?";
    $from = '[email protected]'; 
    $to = '[email protected]'; 
    $subject = 'Customer Inquiry';
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    if (mail($to, $subject, $body, $from)) { 
        echo '<p>Your message has been sent!</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    }


?>

Solution

  • Your 4 Parameter($from) is wrong because it expects an string with header information. you only post a email into it. cange your $from to:

    $from = 'From: [email protected]';