PHPMailer is an encapsulated PHP mail sending class that supports sending emails with HTML content and adding attachments for sending. Unlike PHP itself, the mail() function does not require server environment support. You only need to set up the mail server with relevant information. Implement the email sending function.
This article will use example code to explain how to set up and implement the function of sending HTML and emails with attachments. First, you can go to PHPMailer obtains the latest download package and extracts it to the WEB directory. Then create a sendmail.php file, load the PHPMailer class, and set relevant attribute parameters, such as email server address, sender and recipient, email content, etc. Please see the code for details:
As can be seen from the code, after instantiating PHPMailer, we specify to use SMTP to send emails, set up the SMTP mail server, and enable SMTP authentication. If your mail server does not require authentication, set $mail->SMTPAuth=false , and can be sent without a password. Then set the character set and encoding to support Chinese characters. Note that the original PHPMailer package does not have ideal support for Chinese characters, so you can download the improved package in the helloweba example. Then set the sender and recipient, and add attachments. Note that it is best not to use Chinese for the original name of the attachment. You can specify the Chinese name in AddAttachment(). Then set the html content of the email, and finally send it. The process is clear at a glance. |