search
HomeBackend DevelopmentPHP Tutorialthinkphp实现163、QQ邮箱收发邮件的方法_PHP

用了很长时间去一步一步摸索,终于先在163 网易邮箱上测试成功了,下面就把这个过程分享给大家。

在进入正题这前先看下网易(163)邮箱的服务器地址和端口号:

一、前期准备

使用网易邮箱,当然要注册个账号,这个就不用我多说了,自己去注册。。。

注册完之后,就要去开启 POP3/SMTP/IMAP服务。 在开启服务时,需要客户端授权密码(这里需要手机验证,MD拐弯抹角的要手机号码)。

步骤一:

步骤二:


确定后会弹出下面这样的对话框,也会把这个授权密码发送你的短信里,记住这个授权密码一定要记住


服务开启后,如果没有设置【姓名】,在写邮件发送时会提示设置【姓名】后才能发送邮件,当然也可以提前设置好。。


二、代码部分

PHPMailer下载 ( 下载后把PHPMailer放在Vendor目录下,另外文件中有很多不必要的东西,自己看着处理吧)

细心的同学在 class.phpmailer.php  class.pop3.php  class.smtp.php 这三个文件里看下默认的端口号,其SMTP的默认端口号是25 与 163下的SMTP发件服务器的非SSL协议端口号一样。

html布局:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form action="__URL__/add" method="post" enctype="multipart/form-data">
 收件人邮箱:<input type="text" name="mail"/>
 标题:<input type="text" name="title"/>
 内容<input type="text" name="content"/>
 <input class="button" type="submit" value="发送"/>
 </form>
</body>
</html>

config.php 配置:

'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>'zha****22@163.com',//发件人的邮箱名
'MAIL_PASSWORD' =>'olagbqsyeyhilcwu',//163邮箱发件人授权密码
'MAIL_FROM' =>'zha****22@163.com',//发件人邮箱地址
'MAIL_FROMNAME'=>'天空还下着雪',//发件人姓名
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件

function.php公共函数:

/*
 * 发送邮件
 * @param $to string
 * @param $title string
 * @param $content string
 * @return bool
 * */
function sendMail($to, $title, $content) {
 Vendor('PHPMailer.PHPMailerAutoload');
 $mail = new PHPMailer(); //实例化
 $mail->IsSMTP(); // 启用SMTP
 $mail->Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)
 $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
 $mail->Username = C('MAIL_USERNAME'); //发件人邮箱名
 $mail->Password = C('MAIL_PASSWORD') ; //163邮箱发件人授权密码
 $mail->From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址)
 $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
 $mail->AddAddress($to,"尊敬的客户");
 $mail->WordWrap = 50; //设置每行字符长度
 $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
 $mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
 $mail->Subject =$title; //邮件主题
 $mail->Body = $content; //邮件内容
 $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
 return($mail->Send());
}

add方法调用:

public function add() {
 if(SendMail(

用了很长时间去一步一步摸索,终于先在163 网易邮箱上测试成功了,下面就把这个过程分享给大家。

在进入正题这前先看下网易(163)邮箱的服务器地址和端口号:

一、前期准备

使用网易邮箱,当然要注册个账号,这个就不用我多说了,自己去注册。。。

注册完之后,就要去开启 POP3/SMTP/IMAP服务。 在开启服务时,需要客户端授权密码(这里需要手机验证,MD拐弯抹角的要手机号码)。

步骤一:

步骤二:


确定后会弹出下面这样的对话框,也会把这个授权密码发送你的短信里,记住这个授权密码一定要记住


服务开启后,如果没有设置【姓名】,在写邮件发送时会提示设置【姓名】后才能发送邮件,当然也可以提前设置好。。


二、代码部分

PHPMailer下载 ( 下载后把PHPMailer放在Vendor目录下,另外文件中有很多不必要的东西,自己看着处理吧)

细心的同学在 class.phpmailer.php  class.pop3.php  class.smtp.php 这三个文件里看下默认的端口号,其SMTP的默认端口号是25 与 163下的SMTP发件服务器的非SSL协议端口号一样。

html布局:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form action="__URL__/add" method="post" enctype="multipart/form-data">
 收件人邮箱:<input type="text" name="mail"/>
 标题:<input type="text" name="title"/>
 内容<input type="text" name="content"/>
 <input class="button" type="submit" value="发送"/>
 </form>
</body>
</html>

config.php 配置:

'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>'zha****22@163.com',//发件人的邮箱名
'MAIL_PASSWORD' =>'olagbqsyeyhilcwu',//163邮箱发件人授权密码
'MAIL_FROM' =>'zha****22@163.com',//发件人邮箱地址
'MAIL_FROMNAME'=>'天空还下着雪',//发件人姓名
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件

function.php公共函数:

/*
 * 发送邮件
 * @param $to string
 * @param $title string
 * @param $content string
 * @return bool
 * */
function sendMail($to, $title, $content) {
 Vendor('PHPMailer.PHPMailerAutoload');
 $mail = new PHPMailer(); //实例化
 $mail->IsSMTP(); // 启用SMTP
 $mail->Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)
 $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
 $mail->Username = C('MAIL_USERNAME'); //发件人邮箱名
 $mail->Password = C('MAIL_PASSWORD') ; //163邮箱发件人授权密码
 $mail->From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址)
 $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
 $mail->AddAddress($to,"尊敬的客户");
 $mail->WordWrap = 50; //设置每行字符长度
 $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
 $mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
 $mail->Subject =$title; //邮件主题
 $mail->Body = $content; //邮件内容
 $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
 return($mail->Send());
}

add方法调用:

___FCKpd___3

做完以上工作后,接下来访问地址,通过表单向163(网易)邮箱发送邮件(如:发送给123456@163.com),也可以发送给自己,发送后,就会看到发送成功。下面你可以登录邮箱查看邮件。

QQ邮箱收发邮件

QQ邮箱收发件服务器地址和端口

准备:
1、设置邮箱独立密码
2、开启POP3/SMTP服务

配置:

'MAIL_HOST' =>'smtp.qq.com',//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>'541****34@qq.com',//发件人邮箱名
'MAIL_PASSWORD' =>'s****1241',//qq邮箱发件人独立密码
'MAIL_FROM' =>'541****34@qq.com',//发件人地址
'MAIL_FROMNAME'=>'恋狱',//发件人姓名(qq邮箱昵称)
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件

其他无需改变,完成后不仅可以给QQ邮箱用户发送邮件,也可以给163邮箱用户发送邮件。

以上就是thinkphp实现163等邮箱收发邮件的方法,希望对大家的学习有所帮助。

POST['mail'],

用了很长时间去一步一步摸索,终于先在163 网易邮箱上测试成功了,下面就把这个过程分享给大家。

在进入正题这前先看下网易(163)邮箱的服务器地址和端口号:

一、前期准备

使用网易邮箱,当然要注册个账号,这个就不用我多说了,自己去注册。。。

注册完之后,就要去开启 POP3/SMTP/IMAP服务。 在开启服务时,需要客户端授权密码(这里需要手机验证,MD拐弯抹角的要手机号码)。

步骤一:

步骤二:


确定后会弹出下面这样的对话框,也会把这个授权密码发送你的短信里,记住这个授权密码一定要记住


服务开启后,如果没有设置【姓名】,在写邮件发送时会提示设置【姓名】后才能发送邮件,当然也可以提前设置好。。


二、代码部分

PHPMailer下载 ( 下载后把PHPMailer放在Vendor目录下,另外文件中有很多不必要的东西,自己看着处理吧)

细心的同学在 class.phpmailer.php  class.pop3.php  class.smtp.php 这三个文件里看下默认的端口号,其SMTP的默认端口号是25 与 163下的SMTP发件服务器的非SSL协议端口号一样。

html布局:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form action="__URL__/add" method="post" enctype="multipart/form-data">
 收件人邮箱:<input type="text" name="mail"/>
 标题:<input type="text" name="title"/>
 内容<input type="text" name="content"/>
 <input class="button" type="submit" value="发送"/>
 </form>
</body>
</html>

config.php 配置:

'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>'zha****22@163.com',//发件人的邮箱名
'MAIL_PASSWORD' =>'olagbqsyeyhilcwu',//163邮箱发件人授权密码
'MAIL_FROM' =>'zha****22@163.com',//发件人邮箱地址
'MAIL_FROMNAME'=>'天空还下着雪',//发件人姓名
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件

function.php公共函数:

/*
 * 发送邮件
 * @param $to string
 * @param $title string
 * @param $content string
 * @return bool
 * */
function sendMail($to, $title, $content) {
 Vendor('PHPMailer.PHPMailerAutoload');
 $mail = new PHPMailer(); //实例化
 $mail->IsSMTP(); // 启用SMTP
 $mail->Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)
 $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
 $mail->Username = C('MAIL_USERNAME'); //发件人邮箱名
 $mail->Password = C('MAIL_PASSWORD') ; //163邮箱发件人授权密码
 $mail->From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址)
 $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
 $mail->AddAddress($to,"尊敬的客户");
 $mail->WordWrap = 50; //设置每行字符长度
 $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
 $mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
 $mail->Subject =$title; //邮件主题
 $mail->Body = $content; //邮件内容
 $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
 return($mail->Send());
}

add方法调用:

___FCKpd___3

做完以上工作后,接下来访问地址,通过表单向163(网易)邮箱发送邮件(如:发送给123456@163.com),也可以发送给自己,发送后,就会看到发送成功。下面你可以登录邮箱查看邮件。

QQ邮箱收发邮件

QQ邮箱收发件服务器地址和端口

准备:
1、设置邮箱独立密码
2、开启POP3/SMTP服务

配置:

___FCKpd___4

其他无需改变,完成后不仅可以给QQ邮箱用户发送邮件,也可以给163邮箱用户发送邮件。

以上就是thinkphp实现163等邮箱收发邮件的方法,希望对大家的学习有所帮助。

POST['title'],

用了很长时间去一步一步摸索,终于先在163 网易邮箱上测试成功了,下面就把这个过程分享给大家。

在进入正题这前先看下网易(163)邮箱的服务器地址和端口号:

一、前期准备

使用网易邮箱,当然要注册个账号,这个就不用我多说了,自己去注册。。。

注册完之后,就要去开启 POP3/SMTP/IMAP服务。 在开启服务时,需要客户端授权密码(这里需要手机验证,MD拐弯抹角的要手机号码)。

步骤一:

步骤二:


确定后会弹出下面这样的对话框,也会把这个授权密码发送你的短信里,记住这个授权密码一定要记住


服务开启后,如果没有设置【姓名】,在写邮件发送时会提示设置【姓名】后才能发送邮件,当然也可以提前设置好。。


二、代码部分

PHPMailer下载 ( 下载后把PHPMailer放在Vendor目录下,另外文件中有很多不必要的东西,自己看着处理吧)

细心的同学在 class.phpmailer.php  class.pop3.php  class.smtp.php 这三个文件里看下默认的端口号,其SMTP的默认端口号是25 与 163下的SMTP发件服务器的非SSL协议端口号一样。

html布局:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form action="__URL__/add" method="post" enctype="multipart/form-data">
 收件人邮箱:<input type="text" name="mail"/>
 标题:<input type="text" name="title"/>
 内容<input type="text" name="content"/>
 <input class="button" type="submit" value="发送"/>
 </form>
</body>
</html>

config.php 配置:

'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称
'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证
'MAIL_USERNAME' =>'zha****22@163.com',//发件人的邮箱名
'MAIL_PASSWORD' =>'olagbqsyeyhilcwu',//163邮箱发件人授权密码
'MAIL_FROM' =>'zha****22@163.com',//发件人邮箱地址
'MAIL_FROMNAME'=>'天空还下着雪',//发件人姓名
'MAIL_CHARSET' =>'utf-8',//设置邮件编码
'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件

function.php公共函数:

/*
 * 发送邮件
 * @param $to string
 * @param $title string
 * @param $content string
 * @return bool
 * */
function sendMail($to, $title, $content) {
 Vendor('PHPMailer.PHPMailerAutoload');
 $mail = new PHPMailer(); //实例化
 $mail->IsSMTP(); // 启用SMTP
 $mail->Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)
 $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
 $mail->Username = C('MAIL_USERNAME'); //发件人邮箱名
 $mail->Password = C('MAIL_PASSWORD') ; //163邮箱发件人授权密码
 $mail->From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址)
 $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
 $mail->AddAddress($to,"尊敬的客户");
 $mail->WordWrap = 50; //设置每行字符长度
 $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
 $mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
 $mail->Subject =$title; //邮件主题
 $mail->Body = $content; //邮件内容
 $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
 return($mail->Send());
}

add方法调用:

___FCKpd___3

做完以上工作后,接下来访问地址,通过表单向163(网易)邮箱发送邮件(如:发送给123456@163.com),也可以发送给自己,发送后,就会看到发送成功。下面你可以登录邮箱查看邮件。

QQ邮箱收发邮件

QQ邮箱收发件服务器地址和端口

准备:
1、设置邮箱独立密码
2、开启POP3/SMTP服务

配置:

___FCKpd___4

其他无需改变,完成后不仅可以给QQ邮箱用户发送邮件,也可以给163邮箱用户发送邮件。

以上就是thinkphp实现163等邮箱收发邮件的方法,希望对大家的学习有所帮助。

POST['content'])) { $this->success('发送成功!'); } else { $this->error('发送失败'); } }

做完以上工作后,接下来访问地址,通过表单向163(网易)邮箱发送邮件(如:发送给123456@163.com),也可以发送给自己,发送后,就会看到发送成功。下面你可以登录邮箱查看邮件。

QQ邮箱收发邮件

QQ邮箱收发件服务器地址和端口

准备:
1、设置邮箱独立密码
2、开启POP3/SMTP服务

配置:

___FCKpd___4

其他无需改变,完成后不仅可以给QQ邮箱用户发送邮件,也可以给163邮箱用户发送邮件。

以上就是thinkphp实现163等邮箱收发邮件的方法,希望对大家的学习有所帮助。

Statement
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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software