Σημαντικό: Το IIS 6 (Windows Server 2003) είναι End-of-Life από Ιούλιο 2015. Αυτό το άρθρο είναι για legacy συστήματα. Για σύγχρονα συστήματα (IIS 10+, Windows Server 2016/2019/2022), χρησιμοποιήστε SMTP service ή εξωτερικούς providers (SendGrid, Mailgun, AWS SES).
; php.ini
[mail function]
; Για IIS SMTP service στον ίδιο server
SMTP = localhost
smtp_port = 25
; Αν χρησιμοποιείτε εξωτερικό SMTP (π.χ. Gmail, SendGrid)
; SMTP = smtp.sendgrid.net
; smtp_port = 587
; sendmail_from = noreply@yourdomain.com
; Για authentication (απαιτεί PHP 5.6+ με sendmail_path ή PEAR Mail)
;.auth_username = your_username
;.auth_password = your_password
<?php
$to = 'recipient@example.com';
$subject = 'Test Email from PHP on IIS';
$message = "Hello,\n\nThis is a test email sent from PHP on IIS 6.\n\nRegards,\nSystem";
$headers = "From: sender@yourdomain.com\r\n";
$headers .= "Reply-To: reply@yourdomain.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully";
} else {
echo "Email sending failed";
}
?>
Συστηνόμεται να χρησιμοποιήσετε PHPMailer ή Symfony Mailer:
<?php
// Composer: require phpmailer/phpmailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPAuth = false; // true αν χρειάζεται auth
// Recipients
$mail->setFrom('sender@yourdomain.com', 'System Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->addReplyTo('reply@yourdomain.com', 'Reply Name');
// Content
$mail->isHTML(true);
$mail->Subject = 'HTML Email from PHP on IIS';
$mail->Body = 'Hello!
This is HTML email.
';
$mail->AltBody = 'Hello! This is plain text version.';
// Attachments
$mail->addAttachment('/path/to/file.pdf', 'document.pdf');
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
| Σφάλμα | Αιτία | Λύση |
|---|---|---|
| mail() επιστρέφει false | SMTP service not running / relay denied | Ελέγξτε IIS SMTP service, relay settings, logs |
| Email καθίσταται σε spam | Missing SPF/DKIM/DMARC, poor reputation | Ρυθμίστε DNS records, χρησιμοποιήστε reputable SMTP |
| Timeout | Firewall blocking port 25 | Ανοίξτε firewall, ελέγξτε antivirus |
| 550 Relay not permitted | IP not in relay list | Προσθέστε 127.0.0.1 και server IP στο relay |
C:\WINDOWS\system32\LogFiles\SMTPSVC1\mail.log = "C:\logs\php_mail.log" στο php.initelnet localhost 25 → HELO localhost → MAIL FROM:...Αποφύγετε τον τοπικό SMTP server. Χρησιμοποιήστε:
Όλοι παρέχουν PHP SDKs και διαχειρίζονται deliverability, bounces, reputation.
Πνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.