There are multiple options:
- Execute the command from PHP: https://php.net/manual/bg/function.shell-exec.php
- Use a Queue technology, for example https://kr.github.io/beanstalkd/
- Cronjob that executes the file every given time.
Personally I use option 3. In my projects I have an email_queue
table that holds the emails and a cronjob running every minute to send them.
CREATE TABLE `email_queue` (
`id` int(11) UNSIGNED NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`subject` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`template` varchar(63) COLLATE utf8_unicode_ci NOT NULL,
`variables` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'serialized key => value array',
`priority` tinyint(1) NOT NULL COMMENT 'low 0 - 9 high',
`created_at` datetime NOT NULL,
`sent_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
So basically when a user registers, you insert a record in the DB and the cronjob does the work on the background.