How can one specify a mail server and port using ini_set() in PHP for sending emails?

To specify a mail server and port using ini_set() in PHP for sending emails, you can set the 'SMTP' and 'smtp_port' configuration options. This allows you to define the SMTP server address and port number for sending emails from your PHP script.

// Specify the mail server and port for sending emails
ini_set('SMTP', 'mail.example.com');
ini_set('smtp_port', 25);

// Now you can use the mail() function to send emails
$to = 'recipient@example.com';
$subject = 'Test Email';
$message = 'This is a test email sent from PHP';
$headers = 'From: sender@example.com';

mail($to, $subject, $message, $headers);