How to add line break in php mail function?

Member

by domenico , in category: PHP General , 2 months ago

How to add line break in php mail function?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 2 months ago

@domenico 

To add a line break in the body of an email sent using the PHP mail() function, you can use the " " newline character sequence. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$to = "[email protected]";
$subject = "Hello";
$message = "Dear recipient, 
 This is a line break in an email sent using PHP mail function.";

$headers = 'From: [email protected]' . "
" .
    'Reply-To: [email protected]' . "
" .
    'X-Mailer: PHP/' . phpversion();

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


In this example, the " " sequence is used in the $message variable to create a line break. When the email is sent, the recipient will see the message displayed with a line break in the specified location.