For sending an e-mail message from a PHP script we recommend to use the class Mail from the PEAR Mail.php package.
<?php
require_once 'Mail.php';
$mail = Mail::factory('mail');
$body = 'This is message text...';
$hdrs = array(
'From' => 'sender@example.com',
'Subject' => 'Message subject'
);
$mail->send('receiver@example.com', $hdrs, $body);
?>
For more configuration options you can read documentation related to this class.
The recommended approach is to send e-mails through the SMTP server of your mailbox. This sends the message through our mail servers in the standard way and improves deliverability, including to services such as Gmail.
The following example uses the PHPMailer library. You can install it locally with Composer:
composer require phpmailer/phpmailer
If you do not use Composer directly on the web server, install PHPMailer with Composer on your computer and then upload the vendor directory to the web server together with your PHP script.
In the example script, you only need to enter the login credentials for your own mailbox and the recipient's address.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
// SMTP server
$mail->isSMTP();
$mail->Host = 'smtps.platon.sk';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// Mailbox login credentials
$mail->Username = 'info@yourdomain.com';
$mail->Password = 'MAILBOX_PASSWORD';
// Sender
$mail->setFrom('info@yourdomain.com', 'My website');
// Recipient
$mail->addAddress('example@gmail.com');
// Message content
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Subject = 'Test e-mail';
$mail->Body = '
<h1>Test</h1>
<p>This is a test e-mail sent through the Platon SMTP server.</p>
';
$mail->AltBody = 'This is a test e-mail sent through the Platon SMTP server.';
$mail->send();
echo 'E-mail was sent successfully.';
} catch (Exception $e) {
echo 'E-mail could not be sent: ' . $mail->ErrorInfo;
}
We accept reports of problems or other inducements related to the use of our products and services.
helpdesk@platon.net +421 222 111 321
In case you need any help, contact us by e-mail or by phone.
Give a chance to our online help-center. You can find there more than:
Questions about our products or any specific request? Contact us.