php代码

  1. <?php
  2. // 收件人邮箱地址
  3. $to = 'xxxxxx@qq.com';
  4. // 邮件主题
  5. $title = '测试邮件发送';
  6. // 邮件内容
  7. $msg = '这是一封测试邮件';
  8. // 发件人邮箱(虚拟的,本身发送的时候并不是用这个邮箱)
  9. $from = 'From: xxxxxxx@qq.com';
  10. $flag = mail($to, $title, $msg, $from);
  11. // 打印结果,如果不加var_dump会有空值转换,即null转成‘’
  12. echo var_dump($flag);
  13. ?>

http://www.w3school.com.cn/php/php_ref_mail.asp

在w3cschool里面对这块有些介绍,但没办法直接用,有问题。

淡蓝这里只介绍xampp集成安装的情况,其实都是一样的,自己再去下载一个sendmail也可以,这边xampp已经下载好了

修改一下配置,一共2个配置文件。

在xampp安装目录下

php/php.ini

  1. [mail function]
  2. ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
  3. SMTP = smtp.163.com
  4. smtp_port = 25
  5.  
  6. ; For Win32 only.
  7. ; http://php.net/sendmail-from
  8. sendmail_from = 13514087953@163.com
  9.  
  10. ; 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.
  11. ; 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.
  12. ; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
  13. sendmail_path ="F:\xampp\sendmail\sendmail.exe -t"
  14.  
  15. ; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the F:\xampp\mailoutput folder
  16. ;sendmail_path="F:\xampp\mailtodisk\mailtodisk.exe"
  17.  
  18. ; Force the addition of the specified parameters to be passed as extra parameters
  19. ; to the sendmail binary. These parameters will always replace the value of
  20. ; the 5th parameter to mail(), even in safe mode.
  21. ;mail.force_extra_parameters =
  22.  
  23. ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
  24. mail.add_x_header=Off
  25.  
  26. ; Log all mail() calls including the full path of the script, line #, to address and headers
  27. ;mail.log = "F:\xampp\php\logs\php_mail.log"

主要改这三个配置,这边淡蓝用的是163的smtp服务器,sendmail_path 等于指定一个用来发送邮件的客户端,这里xampp集成了sendmail,也在安装目录下

  1. ;用来发邮件的插件
  2. sendmail_path ="F:\xampp\sendmail\sendmail.exe -t"
  1. 然后修改sendmail目录下的sendmail.ini
  1. [sendmail]
  2.  
  3. ; you must change mail.mydomain.com to your smtp server,
  4. ; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
  5. ; emails delivered via IIS's pickup directory cause sendmail to
  6. ; run quicker, but you won't get error messages back to the calling
  7. ; application.
  8.  
  9. smtp_server=smtp.163.com
  10.  
  11. ; smtp port (normally 25)
  12.  
  13. smtp_port=25
  14.  
  15. ; SMTPS (SSL) support
  16. ; auto = use SSL for port 465, otherwise try to use TLS
  17. ; ssl = alway use SSL
  18. ; tls = always use TLS
  19. ; none = never try to use SSL
  20.  
  21. smtp_ssl=auto
  22.  
  23. ; the default domain for this server will be read from the registry
  24. ; this will be appended to email addresses when one isn't provided
  25. ; if you want to override the value in the registry, uncomment and modify
  26.  
  27. ;default_domain=mydomain.com
  28.  
  29. ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
  30. ; uncomment to enable logging
  31.  
  32. error_logfile=error.log
  33. debug_logfile=debug.log
  34. ; create debug log as debug.log (defaults to same directory as sendmail.exe)
  35. ; uncomment to enable debugging
  36.  
  37. ;debug_logfile=debug.log
  38.  
  39. ; if your smtp server requires authentication, modify the following two lines
  40.  
  41. auth_username=13514087953
  42. auth_password=224119
  43.  
  44. ; if your smtp server uses pop3 before smtp authentication, modify the
  45. ; following three lines. do not enable unless it is required.
  46.  
  47. pop3_server=
  48. pop3_username=
  49. pop3_password=
  50.  
  51. ; force the sender to always be the following email address
  52. ; this will only affect the "MAIL FROM" command, it won't modify
  53. ; the "From: " header of the message content
  54.  
  55. force_sender=13514087953@163.com
  56.  
  57. ; force the sender to always be the following email address
  58. ; this will only affect the "RCTP TO" command, it won't modify
  59. ; the "To: " header of the message content
  60.  
  61. force_recipient=
  62.  
  63. ; sendmail will use your hostname and your default_domain in the ehlo/helo
  64. ; smtp greeting. you can manually set the ehlo/helo name if required
  65.  
  66. hostname=
  1.  

主要修改(其实有些重复的在php.inf文件中就可以不用设置也可以)

  1. ;smtp服务器
  2. smtp_server=smtp.163.com
  3. ;端口
  4. smtp_port=25
  5. ;发件人邮箱名
  6. auth_username=13514087953
  7. ;密码
  8. auth_password=224119
  9. ;发件人邮箱地址
  10. force_sender=13514087953@163.com

用开头的php代码测试一下即可,可以直接在ide中运行

  1.  
  1.  
  1.  

PHP MAIL DEMO(程序代码直接发送邮件)的更多相关文章

  1. RCF进程间通信Demo程序

    在上一篇文章RPC通信框架--RCF介绍中,介绍了RCF的优点,本篇文章从头开始演示如何用RCF编写一个跨进程通信的Demo程序. 将RCF编译为静态库 从官网下载到的源码中包含一个RCF的项目,但是 ...

  2. Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)

    实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...

  3. 集 降噪 美颜 虚化 增强 为一体的极速图像润色算法 附Demo程序

    在2015年8月份的时候,决心学习图像算法. 几乎把当时市面上的图像算法相关书籍都看了一遍, 资金有限,采取淘宝买二手书,长期驻留深圳图书馆的做法, 进度总是很慢,学习算法不得其法. 虽然把手上所有书 ...

  4. 小程序代码包压缩 策略&方案

    微信小程序自推出以来,逐渐发展,目前正受到越来越多的青睐.其中很重要的一点得益于小程序的轻量级特性,每个小程序最多不超过2MB,招之即来挥之即去,相比于几十上百兆的APP,用户进入小程序,或者说,小程 ...

  5. ubuntu14.04上实现faster rcnn_TF的demo程序及训练过程

    安装环境:Ubuntu14.04.显卡Tesla K40C+GeForce GT 705.tensorflow1.0.0.pycharm5.0 说明:原文见博客园,有问题原文下留言,不定期回复.本文作 ...

  6. 32.QT-制作最强电压电阻表盘,可以自定义阴影效果,渐变颜色,图标,文字标签等-附带demo程序

    由于上位机需要绘制电压电阻表盘,如下图所示: 后来,在网上找阿找,还是没找到满意的,索性自己来画控件算了,由于第一次画控件,所以花了我2天时间,才画好 效果图如下: 上图的所有颜色(包括滑动的渐变/单 ...

  7. weex官方demo weex-hackernews代码解读(上)

    一.介绍 weex 是阿里出品的一个类似RN的框架,可以使用前端技术来开发移动应用,实现一份代码支持H5,IOS和Android.最新版本的weex已默认将vue.js作为前端框架,而weex-hac ...

  8. 微信小程序代码片段

    微信小程序代码片段是一种可分享的小项目,可用于分享小程序和小游戏的开发经验.展示组件和 API 的使用.复现开发问题等等.分享代码片段会得到一个链接,所有拥有此分享链接的人可以在工具中导入此代码片段. ...

  9. 使用java mail的网易smtp协议 发送邮件

    package com.enation.newtest; import java.security.GeneralSecurityException; import java.util.Propert ...

随机推荐

  1. js引用类型姿势

    栈 1)var a=new Array(),a.push(a,b,...),a.pop() queue 1)var a=new Array(), a.push(a,b,...),a.shift() a ...

  2. 解读CSS的背景(background)样式

    background-color: 可以为所有的元素设置背景色,这个属性接受任意合法的颜色值,如果希望背景色从元素文本向外少有延伸,只需增加一些内边距(padding). 注意:background- ...

  3. Python学习笔记整理(五)Python中的列表.

    列表和字段,这两种类型几乎是Python所有脚本的主要工作组件.他们都可以在原处进行修改,可以按需求增加或缩短,而且包含任何种类的对象或者被嵌套. 一.列表 列表的主要属性: *任意对象的有序集合 从 ...

  4. ssm+jsp+自定义标签实现分页,可以通用(前端实现)

    近期做了一些分页方面的开发,大致梳理一下 1 jsp页面上关于分页的代码 <tr> <td colspan="9"> <ule1:pagination ...

  5. BZOJ1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 346  Solved: 184 ...

  6. VC++中的类的内存分布(上)

    0.序 目前正在学习C++中,对于C++的类及其类的实现原理也挺感兴趣.于是打算通过观察类在内存中的分布更好地理解类的实现.因为其实类的分布是由编译器决定的,而本次试验使用的编译器为VS2015 RC ...

  7. 为什么新建的管理员账号权限没有Administrator大?

    Administrator是超级管理员,UAC不用确认,跟关了一样. 新建隶属于administrator组的用户,可以关掉UAC. 控制面板>系统和安全>操作中心>更改用户帐户控制 ...

  8. phpcms:七、list.html

    1.列表页{pc:content action="lists" catid="$catid" num="25" order="id ...

  9. 第27讲 UI组件之 ScrollView与底部动态添加数据

    第27讲 UI组件之 ScrollView与底部动态添加数据 1. ScrollView(滚动视图) ScrollView(滚动视图)是实现滚动的一个控件,只需要将需要滚动的控件添加到ScrollVi ...

  10. Hive集成HBase详解

    摘要 Hive提供了与HBase的集成,使得能够在HBase表上使用HQL语句进行查询 插入操作以及进行Join和Union等复杂查询   应用场景 1. 将ETL操作的数据存入HBase 2. HB ...