What are the best practices for setting up a local SMTP server for testing email functionality in PHP?
Setting up a local SMTP server for testing email functionality in PHP involves installing a local mail server like Postfix or Sendmail and configuring it to send emails from your PHP application. This allows you to test email functionality without actually sending emails to real recipients.
// Example PHP code snippet to send an email using a local SMTP server for testing
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email sent from a local SMTP server.";
// Send email using local SMTP server
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
// Send email
if (mail($to, $subject, $message)) {
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}