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 can I use PHPMailer without SMTP secure?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to work with GoDaddy?
- How can I use PHPMailer in Yii 1?
- How can I use PHPMailer with XAMPP on a localhost?
- How can I use PHPMailer with XAMPP on Windows?
- How can I use PHPMailer to send emails through Outlook?
- How can I use PHPMailer to send emails with a Yahoo account?
- How do I view the log for my PHPMailer emails?
- How can I send emails using PHPMailer without using SMTP?
See more codes...