How to give line break in php mail

In PHP, when sending an email using the mail() function or a mail library like PHPMailer, you can use the following methods to insert a line break:

  1. Using \r\n:

    $message = "Hello,\r\nHow are you?";
    mail("[email protected]", "Subject", $message);

    The \r\n sequence is the standard way to insert a line break in plain text emails.

  2. Using <br>:

    $message = "Hello,<br>How are you?";
    mail("[email protected]", "Subject", $message);

    The <br> tag is an HTML tag that represents a line break. However, keep in mind that this will only work if the email client is set to render HTML emails.

  3. Using nl2br():

    $message = "Hello,\nHow are you?";
    $message = nl2br($message);
    mail("[email protected]", "Subject", $message);

    The nl2br() function converts all newline characters (\n) to HTML line breaks (<br>). This is useful if you want to preserve the original line breaks in your email content.

  4. Using PHP_EOL:

    $message = "Hello,". PHP_EOL. "How are you?";
    mail("[email protected]", "Subject", $message);

    The PHP_EOL constant represents the end-of-line character for your operating system (e.g., \r\n on Windows, \n on Unix-like systems).

Remember to adjust the email content according to the email client and recipient's preferences. Some email clients may not render line breaks correctly, so it's always a good idea to test your email content before sending it.