Why can't i send an email using php's mail() function?

The PHP mail() function allows you to send emails directly from a script. However, it requires your server to be correctly configured.

Example:


  mail('test@example.com', 'Subject', 'Message');
  

If the server isn't set up correctly, this simple mail function won't work.

Solution:


  // Ensure you have a mail server configured or use an external library
  mail('test@example.com', 'Subject', 'Message');
  

Beginner's Guide to PHP