What is the best practice for retrieving the name of an SMTP server using PHP for sending emails?

When sending emails using PHP, it is important to retrieve the name of the SMTP server to ensure the emails are delivered correctly. One way to do this is by using the `getmxrr()` function in PHP, which retrieves the MX records for a specified domain. By using this function, you can get the list of SMTP servers associated with the recipient's email domain and choose one to use for sending emails.

$domain = 'example.com';
$mx_records = [];
getmxrr($domain, $mx_records);

$smtp_server = $mx_records[0];
echo "SMTP Server: " . $smtp_server;