Sample PHP Script for Sending Email

If you found this post helpful, kindly share it and show your support :)

You can create a php file sendmail.php in the Document root of your domain with following content.

$sender = '';
$recipient = '';

$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers))
    echo "Message accepted";
    echo "Error: Message not accepted";

You will need to change the with your recipient email address, $subject and $message as per your requirements and 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


Mohammed Noufal

I'm Mohammed Noufal, working as Server Admin for the last 10 years.  In my day-to-day life, l had to face different problems related to Web-hosting. On my website, you can find solutions for different Web-hosting-related problems. Sometimes, I spent hours searching/googling to find a solution. This inspired me to start a website that gives solutions to different Webhosting problems. This website includes basic Linux and windows commands, and different control panels like cPanel, Plesk, DirectAdmin, Webmin & so on. You can find solutions and or suggestions for different Web-hosting related problems from here. Hence I would like to say Errorlogz is your server protector.  I will be glad if Logdetect can help any one of the Server admins to find a solution to his problem.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *