Search code examples
phpemailwampwampserver

How can I send an email using PHP?


I am using PHP on a website and I want to add emailing functionality.

I have WampServer installed.

How do I send an email using PHP?


Solution

  • It's possible using PHP's mail() function. Remember, the mail function will not work on a local server.

    <?php
        $to      = '[email protected]';
        $subject = 'the subject';
        $message = 'hello';
        $headers = 'From: [email protected]'       . "\r\n" .
                     'Reply-To: [email protected]' . "\r\n" .
                     'X-Mailer: PHP/' . phpversion();
    
        mail($to, $subject, $message, $headers);
    ?>
    

    Reference: