Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the PHP Mail sending Class PHPMailer

Shulou Source: shulou.com Published: 2022-06-03 19:03:34 09月27日 Update

This article mainly explains "the use of PHP mail sending class PHPMailer". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the PHP email sending class PHPMailer.

PHPMailer is a mail sending class dedicated to the php language, which is very powerful and enriches the single mail () function of PHP itself. Support SMTP and even attachments.

How to use ◆:

Note before ☆: after decompression, there will be an examples folder in the package with "pop3_before_smtp_test.php" and "test1.php" files in it. Among them, * files teach basic usage (see below), while "test1.php" mainly introduces some new features, which are described in detail in "index.html" in the same folder, and another file "contents.html" is email content, which can be replaced with mail template later to increase email standardization and richness.

☆ basic method: pop3_before_smtp_test.php

< ?php require ‘class.phpmailer.php’; require ‘class.pop3.php’; $pop = new POP3(); // 建立对象,收邮件 $pop->

Authorise ('pop3.example.com'

, 110,30, 'mailer',' password', 1)

/ / set the user information for receiving email

/ / pop3.example.com: pop3 server rewritten into mailbox

/ / for example, 163is pop3.163.com

/ / mailer: user name

/ / password: password

$mail = new PHPMailer ()

/ / create an object and send an email. If you just send an email, you can remove the above.

/ / the pop3 section and the inclusion of class.pop3.php

$mail- > IsSMTP ()

/ / unchanged

$mail- > SMTPDebug = 2

$mail- > IsHTML (true)

/ / whether to enable HTML mail to be sent. Default is false.

/ / to facilitate the use of "mail template" later, let's change it to true

$mail- > Host = 'relay.example.com'

/ / the server that sent the mail

/ / for example, 163mailbox is smtp.163.com

$mail- > From = 'mailer@example.com'

/ / your email address

$mail- > FromName = 'Example Mailer'

/ / your name

$mail- > Subject ='My subject'

/ / email title

$mail- > Body = 'Hello world'

/ / message content, where you can use the new feature to invoke the message

Template, see the back for details.

$mail- > AddAddress ('name@anydomain.

Com', 'First Last')

/ / recipient's mailbox and name

If (! $mail- > Send ())

{

Echo $mail- > ErrorInfo

}

? >

At this point, I believe you have a deeper understanding of "the use of PHP mail sending class PHPMailer". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Mail method file usage content mailbox template name object folder server feature user learning support service practical powerful deeper two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia OPPO Reno Xiaomi Linux