What do these words mean?
PHP is a language many websites use. SMTP is the method used to send email. It is like the postman. Authentication means logging in with a username and password. The mail server checks who you are before it sends your message.
PHP has a basic mail() function. It sends mail with no login, so many receivers do not trust it. SMTP authentication is better.

What you need
- An email account on your domain, like
info@yourdomain.com. You can create one in your hosting control panel. - The mail server name, port and security type. Your welcome email or the panel's email settings page lists them. Ask support if you cannot find them.
- PHPMailer. This is a free PHP library that makes SMTP easy.
Steps
- Install PHPMailer. If you have Composer, run this in your site folder.
composer require phpmailer/phpmailer
This downloads PHPMailer into a folder named vendor. Composer is a tool that fetches PHP libraries.
- Create a file, such as
send.php, and paste the code below. - Replace the example values with your own.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'mail.yourdomain.com';
$mail->SMTPAuth = true;
$mail->Username = 'info@yourdomain.com';
$mail->Password = 'your-email-password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom('info@yourdomain.com', 'Your Name');
$mail->addAddress('friend@example.com');
$mail->Subject = 'Hello';
$mail->Body = 'This is a test message.';
$mail->send();
echo 'Message sent';
} catch (Exception $e) {
echo 'Error: ' . $mail->ErrorInfo;
}
This logs in to your mail server and sends one message. Port 465 uses SSL. For port 587, use ENCRYPTION_STARTTLS instead.
- Upload the file to your hosting.
- Open it in a browser, such as
yourdomain.com/send.php. - Check the inbox of the receiver.
If it fails
- Check the username, password, host and port.
- Make sure the sender address is the same as the logged-in account.
- Read the error text. It often names the problem.
Need help? Open a support ticket.
Quick recap
- SMTP authentication sends mail after logging in.
- It lands in inboxes better than plain
mail(). - Use PHPMailer with your mail host, port, username and password.
- Protect your password and delete test files.