Image

Knowledge base → Simple script to test the php mail function

[Scripts]
Date of publication: 15.11.2022

Periodically, the task arises to check the work of mail for the site, this functionality is especially important for online stores, whose owners receive notifications of new orders by e-mail. If the mail has stopped coming from the site, the first thing to do is to check the operation of the php mail function (for sites on php).

An example of a simple script to test the php mail function.

Let's create a file:

test-email.php
test@DOMAIN.TLD"; $to = "YOUMAIL@DOMAIN.TLD"; $subject = "PHP Mail Test script"; $message = "This is a simple php script to check PHP Mail function"; $headers = "From:" . $from; mail($to,$subject,$message, $headers); echo "Good, test email sent"; ?>

Let's change test@DOMAIN.TLD and YOUMAIL@DOMAIN.TLD to our own, after which we can run the script.


Run script from console:

php test-email.php

The script can also be run from a browser if you are not using a virtual server, but virtual hosting. Receiving a letter will mean that the php mail function is working correctly.





No Comments Yet