Question
How to send a test email using PHP script / PHP mail() function?
Answer
Note: PHP mail() function
should be enabled in php.ini.
- Open domain Document Root directory in Plesk > Domains > example.com > Websites & Domains > httpdocs
- Create simple PHP file (
mail.php,
for example)
-
Add the content following content to the file:
<?php
// Send email
mail('[email protected]','hello','test mail function');
?>Note:
[email protected]
should be changed to the email address of your mail recipient. -
Enable PHP for the domain at Plesk > Domains > example.com > Hosting settings > PHP support
-
Open the PHP page in web browser to send an email: http://example.com/mail.php
- Check the recipient mailbox: a new message should be received. For Plesk administrators: mail server log can be checked:
# grep [email protected] /var/log/maillog
Dec 27 10:55:04 server postfix-local[4278]: postfix-local: [email protected], [email protected], dirname=/var/qmail/mailnames
Dec 27 10:55:05 server dovecot: service=lda, [email protected], ip=[]. msgid=<20171227035504.BF170666DA@server>: saved mail to INBOX
Dec 27 10:55:05 server postfix/pipe[4277]: BF170666DA: to=<[email protected]>, relay=plesk_virtual, delay=0.43, delays=0.05/0.05/0/0.33, dsn=2.0.0, status=sent (delivered via plesk_virtual service)