PHP uses phpmailer to send emails _ PHP Tutorial

Source: Internet
Author: User
Tags php email word wrap
PHP uses phpmailer to send emails. PHP uses phpmailer to send mails phpmailer is a free php mail sending plug-in. we can use phpmailer to log on to our specified email and then use this email to automatically send PHP mail with phpmailer

Phpmailer is a free php email sending plug-in. we can use phpmailer to log on to the specified email and then use this email to send an automatic email to us. now, the free email is like 163, sina supports all of them. let's take a look at the phpmainer 163 email to send an email.

If there is no sending email on the local server, it is a good choice to use the existing SMTP server to send mail. the tool used here is phpmailer (Version 5.2.0), and the SMTP server selects gmail and 163.

1. use scripts sent by gmail

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

Include ("class. phpmailer. php ");

Include ("class. smtp. php ");

// Obtain the content of an external file

$ Mail = new PHPMailer ();

$ Body = file_get_contents('contents.html ');

$ Body = eregi_replace ("[\]", '', $ body );

// Set smtp parameters

$ Mail-> IsSMTP ();

$ Mail-> SMTPAuth = true;

$ Mail-> SMTPKeepAlive = true;

$ Mail-> SMTPSecure = "ssl ";

$ Mail-> Host = "smtp.gmail.com ";

$ Mail-> Port = 465;

// Enter your gmail account and password

$ Mail-> Username = "yourname@gmail.com ";

$ Mail-> Password = "password ";

// Set the sender. it is best not to counterfeit the address.

$ Mail-> From = "yourname@gmail.com ";

$ Mail-> FromName = "Webmaster ";

$ Mail-> Subject = "This is the subject ";

$ Mail-> AltBody = $ body;

$ Mail-> WordWrap = 50; // set word wrap

$ Mail-> MsgHTML ($ body );

// Set the reply address

$ Mail-> AddReplyTo ("yourname@gmail.com", "Webmaster ");

// Add an attachment. the attachment and script are in the same directory.

// Otherwise, enter the complete path

$ Mail-> AddAttachment ("attachment.jpg ");

$ Mail-> AddAttachment ("attachment.zip ");

// Set the email address and name of the email recipient

$ Mail-> AddAddress ("toname@gmail.com", "FirstName LastName ");

// Send emails in HTML format

$ Mail-> IsHTML (true );

// Send an email using the Send method

// Process the data according to the sending result

If (! $ Mail-> Send ()){

Echo "Mailer Error:". $ mail-> ErrorInfo;

} Else {

Echo "Message has been sent ";

}

2. use the 163 email sending script

You only need to change the SMTP configuration and account password. The SMTP configuration is as follows:

?

1

2

3

4

5

6

7

// Set smtp parameters

// Note that the ssl protocol is not required here

$ Mail-> IsSMTP ();

$ Mail-> SMTPAuth = true;

$ Mail-> SMTPKeepAlive = true;

$ Mail-> Host = "smtp.163.com ";

$ Mail-> Port = 25;

If the test passes in the local wampserver environment, you must enable the php_openssl extension.

The above is all the content of this article. I hope you will like it.

Phpmailer is a free php mail sending plug-in. we can use phpmailer to log on to the specified email and then use this email to send it to us automatically...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.