An in-depth discussion of the PHP email sending class PHPMailer_PHP Tutorial

WBOY
Release: 2016-07-15 13:31:49
Original
1117 people have browsed it

PHPMailer is an email sending class specially used in PHP language. It is very powerful and enriches the single mail() function of PHP itself. Supports SMTP and more even attachments.

PHPMailer complies with the LGPL license and can be downloaded for free. The current version is PHPMailer v2.2.1, which was updated on November 16, 2007.
Download address: http://phpmailer.codeworxtech.com/index.php?pg=sf&p=dl
Note: When downloading, the suffixes are .tar.gz and .zip. In fact, they contain The files are all the same, but the compression format is different. .tar.gz has been double-compressed and the file is smaller. WinRAR software can decompress these two formats correctly.

◆How to use:

☆ Previous note: After decompression, there will be an examples folder in the file package, which contains "pop3_before_smtp_test.php" and "test1. php" two files. The first file teaches basic usage (see below), while "test1.php" mainly introduces some new features, which are detailed in "index.html" in the same folder. , and another file "contents.html" is the email content, which can be replaced with an email template in the future to increase the standardization and enrichment of the email.

☆Basic method: pop3_before_smtp_test.php

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>require &lsquo;class.phpmailer.php&rsquo;;  </span></li><li class="alt"><span>require &lsquo;class.pop3.php&rsquo;;  </span></li><li><span>$</span><span class="attribute">pop</span><span> = </span><span class="attribute-value">new</span><span> POP3();  </span></li><li class="alt"><span>// 建立对象,收邮件  </span></li><li><span>$pop-</span><span class="tag">></span><span>Authorise(’pop3.example.com’<br>, 110, 30, ‘mailer’, ‘password’, 1);  </span></span></li>
<li class="alt"><span>// 设置收邮件的用户信息  </span></li>
<li><span>// pop3.example.com:改写成邮箱的 pop3 服务器  </span></li>
<li class="alt"><span>// 例如,163 为 pop3.163.com  </span></li>
<li><span>// mailer:用户名  </span></li>
<li class="alt"><span>// password:密码  </span></li>
<li>
<span>$</span><span class="attribute">mail</span><span> = </span><span class="attribute-value">new</span><span> PHPMailer();  </span>
</li>
<li class="alt"><span>// 建立对象,发邮件,如果仅仅是发邮件可以去掉上面  </span></li>
<li><span>// pop3 部份以及对 class.pop3.php 的包含  </span></li>
<li class="alt">
<span>$mail-</span><span class="tag">></span><span>IsSMTP();  </span>
</li>
<li><span>// 不变  </span></li>
<li class="alt">
<span>$mail-</span><span class="tag">></span><span class="attribute">SMTPDebug</span><span> = </span><span class="attribute-value">2</span><span>;  </span>
</li>
<li>
<span>$mail-</span><span class="tag">></span><span>IsHTML(true);  </span>
</li>
<li class="alt"><span>// 是否使支持 HTML 邮件的发送,默认为 false ,  </span></li>
<li><span>// 为了方便后面使用“邮件模版”,我们把它改为 true  </span></li>
<li class="alt">
<span>$mail-</span><span class="tag">></span><span class="attribute">Host</span><span> = ‘relay.example.com’;  </span>
</li>
<li><span>// 发邮件的服务器  </span></li>
<li class="alt"><span>// 例如,163邮箱 为 smtp.163.com  </span></li>
<li>
<span>$mail-</span><span class="tag">></span><span class="attribute">From</span><span> = ‘mailer@example.com’;  </span>
</li>
<li class="alt"><span>// 你的邮箱  </span></li>
<li>
<span>$mail-</span><span class="tag">></span><span class="attribute">FromName</span><span> = ‘Example Mailer’;  </span>
</li>
<li class="alt"><span>// 你的姓名  </span></li>
<li>
<span>$mail-</span><span class="tag">></span><span class="attribute">Subject</span><span> = ‘My subject’;  </span>
</li>
<li class="alt"><span>// 邮件标题  </span></li>
<li>
<span>$mail-</span><span class="tag">></span><span class="attribute">Body</span><span> = ‘Hello world’;  </span>
</li>
<li class="alt"><span>// 邮件内容,这里可以使用新特性调用邮件<br>模版,具体详情看后面。  </span></li>
<li>
<span>$mail-</span><span class="tag">></span><span>AddAddress(’name@anydomain.<br>com’, ‘First Last’);  </span>
</li>
<li class="alt"><span>// 收件人邮箱和姓名  </span></li>
<li>
<span>if (!$mail-</span><span class="tag">></span><span>Send())  </span>
</li>
<li class="alt"><span>{  </span></li>
<li>
<span>echo $mail-</span><span class="tag">></span><span>ErrorInfo;  </span>
</li>
<li class="alt"><span>}  </span></li>
<li>
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

I hope the knowledge of PHPMailer introduced above can be used as a reference learning material for everyone.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446175.htmlTechArticlePHPMailer is an email sending class specifically used in the PHP language. It is very powerful and enriches the single functionality of PHP itself. mail() function. Supports SMTP and more even attachments. PHPMailer complies with...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template