PHP MAIL DEMO(程序代码直接发送邮件)
php代码
<?php
// 收件人邮箱地址
$to = 'xxxxxx@qq.com';
// 邮件主题
$title = '测试邮件发送';
// 邮件内容
$msg = '这是一封测试邮件';
// 发件人邮箱(虚拟的,本身发送的时候并不是用这个邮箱)
$from = 'From: xxxxxxx@qq.com';
$flag = mail($to, $title, $msg, $from);
// 打印结果,如果不加var_dump会有空值转换,即null转成‘’
echo var_dump($flag);
?>
http://www.w3school.com.cn/php/php_ref_mail.asp
在w3cschool里面对这块有些介绍,但没办法直接用,有问题。
淡蓝这里只介绍xampp集成安装的情况,其实都是一样的,自己再去下载一个sendmail也可以,这边xampp已经下载好了
修改一下配置,一共2个配置文件。
在xampp安装目录下
php/php.ini
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.163.com
smtp_port = 25 ; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = 13514087953@163.com ; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesF:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path ="F:\xampp\sendmail\sendmail.exe -t" ; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the F:\xampp\mailoutput folder
;sendmail_path="F:\xampp\mailtodisk\mailtodisk.exe" ; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header=Off ; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "F:\xampp\php\logs\php_mail.log"
主要改这三个配置,这边淡蓝用的是163的smtp服务器,sendmail_path 等于指定一个用来发送邮件的客户端,这里xampp集成了sendmail,也在安装目录下
;用来发邮件的插件
sendmail_path ="F:\xampp\sendmail\sendmail.exe -t"
然后修改sendmail目录下的sendmail.ini
[sendmail] ; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application. smtp_server=smtp.163.com ; smtp port (normally 25) smtp_port=25 ; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL smtp_ssl=auto ; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify ;default_domain=mydomain.com ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging error_logfile=error.log
debug_logfile=debug.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging ;debug_logfile=debug.log ; if your smtp server requires authentication, modify the following two lines auth_username=13514087953
auth_password=224119 ; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required. pop3_server=
pop3_username=
pop3_password= ; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content force_sender=13514087953@163.com ; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content force_recipient= ; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required hostname=
主要修改(其实有些重复的在php.inf文件中就可以不用设置也可以)
;smtp服务器
smtp_server=smtp.163.com
;端口
smtp_port=25
;发件人邮箱名
auth_username=13514087953
;密码
auth_password=224119
;发件人邮箱地址
force_sender=13514087953@163.com
用开头的php代码测试一下即可,可以直接在ide中运行
PHP MAIL DEMO(程序代码直接发送邮件)的更多相关文章
- RCF进程间通信Demo程序
在上一篇文章RPC通信框架--RCF介绍中,介绍了RCF的优点,本篇文章从头开始演示如何用RCF编写一个跨进程通信的Demo程序. 将RCF编译为静态库 从官网下载到的源码中包含一个RCF的项目,但是 ...
- Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)
实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...
- 集 降噪 美颜 虚化 增强 为一体的极速图像润色算法 附Demo程序
在2015年8月份的时候,决心学习图像算法. 几乎把当时市面上的图像算法相关书籍都看了一遍, 资金有限,采取淘宝买二手书,长期驻留深圳图书馆的做法, 进度总是很慢,学习算法不得其法. 虽然把手上所有书 ...
- 小程序代码包压缩 策略&方案
微信小程序自推出以来,逐渐发展,目前正受到越来越多的青睐.其中很重要的一点得益于小程序的轻量级特性,每个小程序最多不超过2MB,招之即来挥之即去,相比于几十上百兆的APP,用户进入小程序,或者说,小程 ...
- ubuntu14.04上实现faster rcnn_TF的demo程序及训练过程
安装环境:Ubuntu14.04.显卡Tesla K40C+GeForce GT 705.tensorflow1.0.0.pycharm5.0 说明:原文见博客园,有问题原文下留言,不定期回复.本文作 ...
- 32.QT-制作最强电压电阻表盘,可以自定义阴影效果,渐变颜色,图标,文字标签等-附带demo程序
由于上位机需要绘制电压电阻表盘,如下图所示: 后来,在网上找阿找,还是没找到满意的,索性自己来画控件算了,由于第一次画控件,所以花了我2天时间,才画好 效果图如下: 上图的所有颜色(包括滑动的渐变/单 ...
- weex官方demo weex-hackernews代码解读(上)
一.介绍 weex 是阿里出品的一个类似RN的框架,可以使用前端技术来开发移动应用,实现一份代码支持H5,IOS和Android.最新版本的weex已默认将vue.js作为前端框架,而weex-hac ...
- 微信小程序代码片段
微信小程序代码片段是一种可分享的小项目,可用于分享小程序和小游戏的开发经验.展示组件和 API 的使用.复现开发问题等等.分享代码片段会得到一个链接,所有拥有此分享链接的人可以在工具中导入此代码片段. ...
- 使用java mail的网易smtp协议 发送邮件
package com.enation.newtest; import java.security.GeneralSecurityException; import java.util.Propert ...
随机推荐
- javascript使用for循环批量注册的事件不能正确获取索引值的解决方法
今天遇到一个问题,那就是当使用for循环批量注册事件处理函数,然后最后通过事件处理函数获取当前元素的索引值的时候会失败,先看一段代码实例: <script type="text/jav ...
- Codeforces Round #318(Div 1) 573A, 573B,573C
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 这场的前两题完全是手速题...A题写了7分钟,交的时候已经500+了,好在B题出的 ...
- 《Linux多线程服务器端编程》读书笔记第3章
<Linux多线程服务器端编程>第3章主要讲的是多线程服务器的适用场合与常用的编程模型. 1.进程和线程 一个进程是"内存中正在运行的程序“.每个进程都有自己独立的地址空间(ad ...
- css技巧之如何实现ul li边框重合
提到边框重合,我们不妨打开淘宝首页浏览主体分类内容板块瞧瞧---亲,你看到了,正是这个,边框重合.其实我们不难发现,这个效果并不难,只是我们没有真正的动手做过而已,所以不知道怎么做,那么下面就是一个很 ...
- AngularJS自定义表单验证
<!doctype html> <html ng-app="myApp"> <head> <script src="G:\\So ...
- While installing plugin in eclipse luna, “Unable to acquire PluginConverter service” and “No repository found” errors appear in logs
http://stackoverflow.com/questions/18767831/while-installing-plugin-in-eclipse-luna-unable-to-acquir ...
- Lazy Load Plugin for jQuery延迟加载测试成功
一直需要的功能,网页图片太多时对于降低网络流量超有用. 最新的V1.9.3版本其实已不用修改就可以起作用了. 不用网上说的要自己修改代码.
- PSAM 卡的应用操作方法
PSAM 卡的应用 PSAM 功能 终端安全存储模块 PASM 常用于 脱机交易的 安全认证 脱机交易的流程 1.卡片对持卡人的认证(防止 ...
- C++中实现回调机制的几种方式(一共三种方法,另加三种)
(1)Callback方式Callback的本质是设置一个函数指针进去,然后在需要需要触发某个事件时调用该方法, 比如Windows的窗口消息处理函数就是这种类型. 比如下面的示例代码,我们在Down ...
- CentOS6.5切换 语言(附带6.5官方下载地址)
1 在终端中输入命令[sudo vim /etc/sysconfig/i18n]来编辑i18n文件, 2 把“zh_CN.UTF-8”修改为“en_US.UTF-8”, 3 保存修改并退出,如果提示这 ...