1. php的mail()函数是可以发送邮件的 , 但是一直就没有测试成功过 , 现在总结一下原因 :

php的mail函数 基于sendmail命令来发送 , sendmail命令需要安装postfix软件

2.查看php的配置项sendmail_path  ,这个就是mail函数调用的底层命令 ,    php  -i|grep sendmail

3.安装postfix软件 才可以使用sendmail命令 , apt-get install postfix

当软件安装完成后 , 在命令行测试一下是否能够发送成功

建立一个eml的文本文件 ,内容是最主要的几个邮件协议头

Subject: title-testing
From: shihan2@sopans.com
To: 630892807@qq.com Sorry, I'm testing. ~_~
 /usr/sbin/sendmail -t -i -f shihan2@sopans.com < 2.eml

-f参数后面的是和from值对应的 , 如果对应不上会报错 , 可以查看日志文件/var/log/mail.log , 来看错误原因和是否成功

如果from值对应不上 , 日志中提示的信息

发送成功后对应的信息 , 250ok

4. 修改php的配置文件 , 使用php函数进行发信

我修改了这个配置文件 ,  /etc/php/7.0/cli/php.ini  , from参数给写死了, 测试的时候 , 如果不写这个from邮箱 ,发送一直失败 , 提示501 Syntax: MAIL FROM: <address> (in reply to MAIL FROM command))  ,mail from和信体的from对应不上

查看下配置

建立一个php文件

<?php

$to='630892807@qq.com';
$subject = '测试一下'; $message = '我来测试';
$headers[] = 'From: shihan2@sopans.com';
mail($to, $subject, $message, implode("\r\n", $headers));

测试成功

  

  

  

[PHP] 邮件发送mail()函数失败问题 sendmail命令与postfix的更多相关文章

  1. 简单的邮件发送mail.jar

    public class MailSender { final static Logger logger = Logger.getLogger(MailSender.class); /** * 发送简 ...

  2. 邮件发送工具类 SendMail.java

    package com.util; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.Simp ...

  3. shell邮件发送功能实现

    本文中以163邮箱为例,测试shell邮件发送功能.常见的工具有:mailx.sendmail.mutt等. 1.设置邮件客户端 (1)启用pop3.smtp服务,以支持第三方客户端支持 (2)设置授 ...

  4. SpringBoot 2.X从0到1实现邮件发送功能

    Spring中提供了JavaMailSender接口实现邮件发送功能,在SpringBoot2.X中也封装了发送邮件相关的Starter并且提供了自动化配置. 本文目录 一.添加对应的Starter二 ...

  5. Telnet 模拟邮件发送过程

    Telnet 模拟邮件发送过程 windows要提前开启Telnet客户端的功能,再按照下面步骤完成邮件发送: 1.通过 cmd 进入命令窗口 2.连接要发送邮件的服务器:telnet smtp.al ...

  6. 浏览器访问php脚本通过sendmail用mail函数发送邮件

    前几天做项目遇到这样的一个问题:当某一个结点下有新的文章发表的时候,以邮件的形式通知该结点下的所有用户.这就需要用到邮件发送的功能. 因为项目是php语言做的,所以最简单的方法就是使用php自带的函数 ...

  7. PHP 在windows下配置sendmail,通过 mail() 函数发送邮件

    php mail()函数在windows不能用,需要安装sendmail. 1. 从http://glob.com.au下载sendmail.zip 2. 解压sendmail.zip到目录下(最好使 ...

  8. ThinkPHP邮件发送S(Smtp + Mail + phpmailer)

    三种邮件发送介绍:(Smtp,Mail以及phpmailer)ThinkPhp 框架下开发. 邮件发送配置先前准备(用该账号做测试用):(这里用新浪邮箱服务器)将自己的新浪邮箱开通 POP3/SMTP ...

  9. ThinkPHP邮件发送函数示例

    ThinkPHP邮件发送函数示例详解 /** * 发送邮件 * @param $tomail * @param $subject * @param $body * @param string $con ...

随机推荐

  1. linux学习:网络(防火墙)及系统安全相关命令学习

    指令: top.htop.free.pstree.lsof.ifconfig.w3m.tcpdump.netstat.nmap.ufw 网络: top    #查看内存,cpu,进程之间的状态.hto ...

  2. 1.8 Double-Opening and Virtual Machine

    Since plug-in will be replaced by RN as following years, what is the future of plug-in? the answer i ...

  3. 阿里分布式事务解决方案-GTS

    摘要: 本文将深入和大家探讨微服务架构下,分布式事务的各种解决方案,并重点为大家解读阿里巴巴提出的分布式事务解决方案----GTS.该方案中提到的GTS是全新一代解决微服务问题的分布式事务互联网中间件 ...

  4. 举例子来说明Python引用和对象

    今天看到这么一句奇怪的话: python中变量名和对象是分离的:最开始的时候是看到这句话的时候没有反应过来.决定具体搞清楚一下python中变量与对象之间的细节.(其实我感觉应该说 引用和对象分离 更 ...

  5. JAVA设计模式—观察者模式和Reactor反应堆模式

    被观察者(主题)接口 定义主题对象接口 /**抽象主题角色: 这个主题对象在状态上发生变化时,会通知所有观察者对象 也叫事件对象 */ public interface Subject { //增加一 ...

  6. [Swift]LeetCode56. 合并区间 | Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. Example 1: Input: [[1,3],[2,6],[8, ...

  7. [Swift]LeetCode219. 存在重复元素 II | Contains Duplicate II

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  8. [Swift]LeetCode416. 分割等和子集 | Partition Equal Subset Sum

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  9. [Swift]LeetCode466. 统计重复个数 | Count The Repetitions

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  10. [Swift]LeetCode740. 删除与获得点数 | Delete and Earn

    Given an array nums of integers, you can perform operations on the array. In each operation, you pic ...