Skip to content
Advertisement

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 = "yunishuseynzade1102@gmail.com";
    $message = "Hello how are you?";
    $from = 'dj.yunis.official@gmail.com'; 
    $to = 'yunishuseynzade1102@gmail.com'; 
    $subject = 'Customer Inquiry';
    $body = "From: $namen E-Mail: $emailn 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>'; 
    }


?>

Advertisement

Answer

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: dj.yunis.official@gmail.com';
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement