Simple PHP Mail Script

<?php

    $to = 'test@mydomain.com';
    $subject = 'PHP mail test';
    $message = 'This is body of email';
    $from = "From: FirstName LastName <test@yourdomain.com>";
    mail($to,$subject,$message,$from);

?>

This is a simple PHP mail script. Usually I use it for testing purposes.

Copy and paste this into a test-mail.php file:

<?php 
    $to = 'test@mydomain.com';
    $subject = 'PHP mail test';
    $message = 'This is body of email';
    $from = "From: FirstName LastName <test@yourdomain.com>";
    mail($to,$subject,$message,$from);
?>

Then to run the script just run:

php test-mail.php

This is very useful for testing this on a Linux machine, so if you need to send a few emails you can do something like this:

for i in {1..3}; do php test-mail.php; done

This would run the test PHP script 3 times.

Snippet By Dev Dojo

ยท

Created June 12th, 2021