phpmailerHow do I use PHPMailer to add an address?
Using PHPMailer to add an address is a simple process. Here is an example code block to illustrate how to do it:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->addAddress('[email protected]', 'John Doe');
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
This code will add the address '[email protected]' and name 'John Doe' to the recipient list. The addAddress()
method takes two parameters: the email address and the name of the recipient. If the message is successfully sent, the output will be 'Message has been sent'.
The following are the parts of this code and their explanations:
require 'PHPMailerAutoload.php';
- This imports the PHPMailer library.$mail = new PHPMailer;
- This creates a new PHPMailer instance.$mail->addAddress('[email protected]', 'John Doe');
- This adds an address to the recipient list.if(!$mail->send()) {...} else {...}
- This checks if the message is successfully sent and outputs an appropriate message.
Here are some relevant links to learn more about PHPMailer:
More of Phpmailer
- How can I configure PHPMailer to support Polish characters?
- How can I use PHPMailer in Yii 1?
- How can I configure PHPMailer to work with GoDaddy?
- How can I set up PHPMailer to use Zimbra SMTP?
- How can I use PHPMailer without SMTP secure?
- How do I determine which version of PHPMailer I'm using?
- How can I use PHPMailer to send emails with a Yahoo account?
- How do I use PHPMailer to attach a ZIP file?
- How can I send emails using PHPMailer without using SMTP?
- How do I update PHPMailer?
See more codes...