phpmailerHow do I add a new line character in a PHPMailer message?
Adding a new line character in PHPMailer message is quite simple. You can use the following example code block to do it:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Body = "This is the first line\nThis is the second line";
echo $mail->Body;
The output of the above code will be:
This is the first line
This is the second line
Code explanation
require 'PHPMailerAutoload.php': This includes the PHPMailer library.$mail = new PHPMailer: This creates a new PHPMailer instance.$mail->Body = "This is the first line\nThis is the second line": This sets the body of the message and adds a new line character (\n) between the two lines.echo $mail->Body: This outputs the body of the message.
Helpful links
More of Phpmailer
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to work with GoDaddy?
- How can I set up PHPMailer to use Zimbra SMTP?
- How can I configure PHPMailer to support Polish characters?
- How can I use PHPMailer with XAMPP on a localhost?
- How can I use PHPMailer without SMTP secure?
- How do I use PHPMailer to send a file?
- How can I set the encoding for PHPMailer?
- How do I check which version of PHPMailer I'm using?
- How do I configure PHPMailer to use TLS 1.2?
See more codes...