phpmailerHow do I create a body template for PHPMailer?
Creating a body template for PHPMailer is quite easy. You just need to use the $mail->Body
property of the PHPMailer class. This property is used to set the body of the email.
Example code
$mail = new PHPMailer();
$mail->Body = 'This is the body of the email';
The $mail->Body
property accepts a string, so you can use HTML and CSS to format the email body. You can also use variables in the string to make the body dynamic.
Example code
$name = 'John Doe';
$mail = new PHPMailer();
$mail->Body = 'Hello, <b>$name</b>, welcome to our website!';
Output example
Hello, John Doe, welcome to our website!
Code explanation
$mail = new PHPMailer();
- This line creates a new instance of the PHPMailer class.$mail->Body = 'This is the body of the email';
- This line sets the body of the email.$name = 'John Doe';
- This line creates a variable for the name.$mail->Body = 'Hello, <b>$name</b>, welcome to our website!';
- This line sets the body of the email using the variable for the name.
Helpful links
More of Phpmailer
- How do I use PHPMailer to attach a ZIP file?
- How can I use PHPMailer without SMTP secure?
- How can I configure PHPMailer to support Polish characters?
- How can I configure PHPMailer to work with GoDaddy?
- How do I view the log for my PHPMailer emails?
- How can I set up PHPMailer to use Zimbra SMTP?
- How can I use PHPMailer in Yii 1?
- How do I use PHPMailer with Yii2?
- How can I use PHPMailer with XAMPP on Windows?
- How can I use PHPMailer with React?
See more codes...