The mail() function is PHP's default method for sending messages. While simple to implement, it has serious technical drawbacks:
systemuser@server.papaki.gr), which does not correspond to a real, authorized email account.mail() function fail these checks, leading receiving servers to reject them or route them straight to Spam.To ensure your website's emails land reliably in your recipients' inboxes, all outgoing messages should be sent through an authenticated SMTP mail server, using a valid email account on your domain (e.g., info@yourdomain.gr or noreply@yourdomain.gr).
mail.yourdomain.gr, provided that the corresponding DNS record has been created in your domain's active DNS zoneinfo@yourdomain.gr)If you run an established content management system or e-commerce platform, you do not need to write any PHP code:
Mail to SMTP and fill in your server and port credentials.For custom-built websites and web applications, the standard industry practice is using the PHPMailer library, which automatically manages message headers, UTF-8 encoding, attachments, and secure SMTP authentication.
Sample Implementation:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
// Server Settings
$mail->isSMTP();
$mail->Host = 'smtp-gr.securemail.pro'; // Your SMTP server
$mail->SMTPAuth = true;
$mail->Username = 'info@yourdomain.gr'; // Your email address
$mail->Password = 'YourEmailPasswordHere'; // Your email password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // SSL/TLS
$mail->Port = 465; // Port 465 (or 587 with STARTTLS)
$mail->CharSet = 'UTF-8'; // Character set for multilingual support
// Sender & Recipients
$mail->setFrom('info@yourdomain.gr', 'Your Business Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
// Message Content
$mail->isHTML(true);
$mail->Subject = 'Email Subject Here';
$mail->Body = '<b>Hello!</b> This is a test email sent via authenticated SMTP.';
$mail->AltBody = 'This is the plain text version for email clients that do not support HTML.';
$mail->send();
echo 'Message has been sent successfully!';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
If you must temporarily keep using PHP's native mail() function before updating your codebase to SMTP, you must at least specify the fifth parameter (-f) to set a valid envelope sender address from your domain:
mail('recipient@example.com', 'Email Subject', 'Message body goes here', null, '-finfo@yourdomain.gr');
-f parameter must be immediately adjacent to your sender email address (without spaces).Contact our experts, they will be happy to help!
Contact us