What are the common pitfalls when trying to send emails using PHP and an external server?

One common pitfall when trying to send emails using PHP and an external server is not properly configuring the email settings, such as the SMTP server, port, username, and password. To solve this issue, make sure to double-check and correctly set these configurations in your PHP script.

// Set the SMTP server and port
$smtpServer = 'smtp.example.com';
$port = 587;

// Set the username and password for authentication
$username = 'your_email@example.com';
$password = 'your_password';

// Set the email settings
$mail->isSMTP();
$mail->Host = $smtpServer;
$mail->Port = $port;
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;