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 can I configure PHPMailer to ignore TLS certificate errors?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer with OAuth2 authentication for Microsoft accounts?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to support Polish characters?
- How can I set up PHPMailer to use Zimbra SMTP?
- How do I configure PHPmailer to use Zoho SMTP?
- How can I use PHPMailer without SMTP secure?
- How can I resolve the issue of my PHPmailer username and password not being accepted?
- How do I configure PHPMailer to use TLS 1.2?
See more codes...