在PHP中施用SMTP发送邮件
在PHP中使用SMTP发送邮件
今天一个朋友问我如何在PHP中发送邮件,遂我让他去百度谷歌一搜一大把。良久之后我问他问题解决与否,他很失落地表示网上的教程都是一个模板,按照他们的来会有一些问题,所以我整理了一下,准备重新把这个方法总结一下,以便留作将来参考。
?
?
1.什么是SMTP
SMTP的全称是Simple?Mail?Transfer?Protocol,即简单邮件传输协议,简单来理解,这个玩意就是拿来发送邮件的,至于具体怎么去实现的,完全不需要深究,因为我只需要它的这个功能而已。
?
?
2.使用相应的软件来实现SMTP
我选择了hMailServer,个人感觉这个软件还不错,具体下载地址可以到这里寻
找最新版本
http://www.hmailserver.com/index.php?page=download
?
?
3.配置hMailServer
软件下好了,至于安装那都是千篇一律了,安装好之后进行登录,重点讲配置这一块。
?
?
?
首先,看看Status中的服务是否启动了,启动了之后进行下一步
?
?
?
接着找到Domain,选择右边框体的Add
?
?
?
?
接着,选中General选项卡,在Domain中写入你想要的域名,比如我使用benzlee.com。这里有个误区,很多人问,在这里不应该填写163.com或者sina.com或者tom.com这些邮箱吗?就在这一点中,很多教程都对大家产生了误导——我现在是用自己的电脑作为服务器发送邮件,为什么还要写上他们的域名?我当然可以自定义自己喜欢的域名,跟什么163.com什么sina.com完全没有任何关系。
?
?
?
?
然后,选中选项卡Limits,按照下图所示进行数据设置,这里主要是对发送邮件大小的一些限制,可以根据自己的需要调节
?
?
?
?
接下来,该要创建自己的邮件帐户了,也就是说,你使用该帐户形式发送邮件。选择benzlee.com下的Accounts,点击Add,添加自己的帐户信息
?
?
?
?
在General选项卡的Address写入自己想要的帐户名,比如我设定为benzlee,输入自己的密码,我默认为空(这个密码是随意定的,除非你要认证该帐户),设定Maximum?size?为1000,这样,帐户就创建好了
?
?
?
?
然后,选择Setting->Protocols,将IMAP前面的勾去掉
?
?
?
接着,选择SMTP,切换到Delivery?of?e-mail选项卡,根据图中进行设置
?
?
?
然后,选择Advanced->Auto-ban,把Enabled前面的勾去掉
?
?
?
?
然后切换到IP?Ranges的My?Computer,进行如下设置
?
?
?
?
最后切换到Internet下,进行如下设置
?
?
?
?
搞定,hMailServer配置完毕。进入下一步
?
4.修改php.ini的内容,修改内容如下:
?1)修改SMTP?=?localhost
?2)修改[email protected],这里特别注意要去掉前面的分号,否则该句子算是被注释。这个句子是指该e-mail是由谁发送出去的,[email protected]就是刚才自己配置的邮件帐户。
?3)修改完成之后千万记得重启下Apache,否则就没有效果了。
?
5.自己写一个mail.php程序,可以使用如下代码:
?
$content?=?"This?is?a?mail?from?benzlee";???????//此处为邮件内容
$content?=?wordwrap($content,70);?????//?如果一行大于?70?个字符,使用?wordwrap()
mail("[email protected]","This?Is?My?SMTP",$content);????//调用PHP自带的mail函数,第一个参数为发送对象,第二个为邮件标题,第三个为邮件内容。
?>
?
[email protected]就是你想发送邮件的信箱地址,可以改成自己常用的信箱进行验证。
?
6.最后调用这个写好的php文件就能发送邮件了,大功告成。
没有收到自己的邮件?别纠结,去垃圾邮件箱看看你就知道了。。
最后。转载请注明出处,道理你懂的。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
