Sample PHP Script for Sending Email
You can create a php file sendmail.php in the Document root of your domain with following content.
<?PHP
$sender = 'sender@domain.com';
$recipient = 'recipient@domain.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
You will need to change the recipient@domain.com with your recipient email address, $subject and $message as per your requirements and sender@domain.com with sender email address.
Note :- Please set necessary ownership and permission for the file.
That’s it 🙂
You can now test the file by accessing it from the browser like https://domain.com/sendmail.php