What role does DNS lookup play in potential delays when sending emails via SMTP in PHP?

DNS lookup can potentially cause delays when sending emails via SMTP in PHP because the server needs to resolve the domain name of the email recipient to an IP address. To reduce these delays, it is recommended to use an IP address directly instead of a domain name in the SMTP settings. This bypasses the DNS lookup process and can improve the speed of email delivery.

// Set SMTP settings with IP address instead of domain name
$mail->isSMTP();
$mail->Host = 'xxx.xxx.xxx.xxx'; // IP address of the SMTP server
$mail->SMTPAuth = true;
$mail->Username = 'your_smtp_username';
$mail->Password = 'your_smtp_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;