To send an email in PHP, use the mail()
function. To send a letter, you need to specify the recipient’s address, the subject of the letter, and the text of the message, as well as a special From header, indicating the sender:
<?php
mail('receiver@example.com', 'Subject of the letter', 'Text of the letter', 'From: sender@example.com');
?>
If this code is executed on the hosting, the letter will be sent and will arrive to the recipient, but if we use OSPanel, then by default all our letters will simply be written to the log file (located in the .\OSPanel\logs\mail
folder).
[!info] Additional information on this issue can be found in the PHP documentation.
Setting up sending email in OSPanel 6.0 via remote SMTP
Install the windows application sendmail.exe
SendMail is a program that can send emails via the SMTP protocol.
In previous versions of OSPanel the sendmail.exe program was included, but in version 6.0 it is not, therefore:
download sendmail.zip and unzip its contents (for example to the folder .\OSPanel\sendmail
)
Configure SendMail
In the configuration file С:\sendmail\sendmail.ini
specify your values:
smtp_server=
smtp_port=
auth_username=
auth_password=
[!note] Parameters should be specified without quotes.
Example of SendMail setup for popular hosting Timeweb
Sending emails from scripts on websites can be done via SMTP server or via Exim (message transfer agent) installed on each server of Timeweb.
The following details are used for sending via SMTP:
- server for sending email — smtp.timeweb.ru,
- port — 25 or 2525,
- user login matches email inbox,
- password from email inbox.
Configuring the OSPanel server
The settings for Open Server Panel and its modules are stored in the file .\OSPanel\config\program.ini
. Disable the built-in SMTP server in the [smtp] section:
...
[smtp]
;open_email_after_saving = off
;saved_email_extension = .eml
;smtp_port = 25
smtp_server = off
...
Next, you need to edit the PHP module settings file with the version activated for our project (for example, PHP-8.3) .\OSPanel\config\PHP-8.3\default\templates\php.ini
:
...
;--------------------------------
; Mail
;--------------------------------
mail.add_x_header = Off
;mail.force_extra_parameters =
;mail.log = "{root_dir}/logs/{module_name}/php_mail.log"
;mail.mixed_lf_and_crlf = Off
;sendmail_from=
;sendmail_path =
;SMTP = "{api_domain}"
;smtp_port = {smtp_port}
sendmail_path = "{root_dir}/sendmail/sendmail.exe -t"
...
or instead of the added line in the file .\OSPanel\config\PHP-8.3\default\templates\php.ini
:
sendmail_path = "{root_dir}/sendmail/sendmail.exe -t"
add line
php_admin_value sendmail_path = "{root_dir}/sendmail/sendmail.exe -t"
at the end of the file .\OSPanel\config\PHP-8.3\default\templates\httpd.conf
:
...
</VirtualHost>
</IfModule>
</Macro>
php_admin_value sendmail_path = "{root_dir}/sendmail/sendmail.exe -t"
# -----------------------------------------------------------------------------------
# Virtual Hosts
# -----------------------------------------------------------------------------------
...
[!warning] Important: To apply the changes, you need to restart Open Server Panel.
As a result, sending mail should work.