$to = 'example@email.com'; $subject = 'Hello World'; $message = 'This is a test email.'; $headers = "From: My email"; mail($to, $subject, $message, $headers);
$mail = new PHPMailer(); $mail->setFrom('myemail@email.com', 'My Name'); $mail->addAddress('recipient@email.com'); $mail->Subject = 'Hello World'; $mail->Body = 'This is a test email.'; $mail->send();In this example, the `$mail->Subject` property is used to set the subject line of the email. This library provides more options to configure and send emails, making it a more robust solution. Both of these examples illustrate the use of the `setSubject` method to set the subject line of an email. The specific library being used may vary, but the method itself has the same functionality.