How to send e-mail in PHP without SMTP
If you don’t want to use or define your SMTP, you can use mail()
function without defining SMTP. It should use the local mail server instead.
Info: This method won’t work on localhost and other servers that have no SMTP configured on their own. E-mails sent with this method sometimes may not arrive or may end up in spam. This is not the most secure method and I do not recommend it for sending emails. It can be used for testing and educational purposes, but I advise against using it in serious production environments.
In most cases, it is better to define SMTP on your own instead of using the server’s one. In most cases, for sending e-mails in PHP, I’d recommend external libraries such as PHPMailer.
<?php
mail('to', 'subject', 'message', 'From: [email protected]');
?>
Example:
<?php
$to = "[email protected]";
$from = "[email protected]";
$subject = "Hello";
$message = 'Hello World!';
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
?>