目录
分步说明:
首页 后端开发 php教程 在php里从本地经过msmtp发送邮件

在php里从本地经过msmtp发送邮件

Jun 13, 2016 am 10:30 AM
apache etc mail

在php里从本地通过msmtp发送邮件

参看http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php- through-msmtp-using-gmail-account-on-linux/? 的步骤:

?

?

分步说明:

?

  1. 首先,请按照本教程操作:
    在您的 Linux 机器上安装 msmtp 并将其配置为与 Gmail 一起使用。

    ?

    Msmtp 是高度可配置的,您可以轻松地将其配置为与任何 smtp 服务器一起使用。如果您希望将任何其他服务与 msmtp 一起使用,您可以阅读其手册并进行配置。
    仅当您已成功配置并能够发送测试消息时,才继续下一步。

  2. 在文本编辑器中打开 php.ini。
    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>etc<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>php5<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>apache2<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>php.ini
    登录后复制

    搜索“sendmail_path”并将其更改为

    sendmail_path = <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #ff0000;">'/usr/bin/msmtp -t'</span>
    登录后复制

    保存文件并退出文本编辑器。
    请注意,如果您不使用 Ubuntu,您的 msmtp 路径可能会有所不同。您可以通过以下方式找到可执行文件的路径:

    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">which</span> msmtp
    登录后复制

  3. Restart apache:

    ?

    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">sudo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>etc<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>init.d<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>apache2 restart
    登录后复制

    OR

    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #c20cb9; font-weight: bold;">sudo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>opt<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>lampp<span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-weight: bold;">/</span>lampp restart
    登录后复制

  4. Everything’s done. Lets test if the mail() function is working now:
    <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">if</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">(</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #990000;">mail</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">(</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">[email&#160;protected]'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">,</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Test mail from localhost'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">,</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Working Fine.'</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">)</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #009900;">)</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">;</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">echo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Mail sent'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">;</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">else</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #b1b100;">echo</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #0000ff;">'Error. Please check error log.'</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #339933;">;</span>
    登录后复制

    Replace the [email protected] with your own username, save it into a php file along with php delimeters in your virtual host root folder and execute it through the browser. You should receive a mail.

    跟上述步骤大同小异。

    msmtp在ubuntu下apt-get install msmtp就可以安装, 安装完后, msmtp --ver 查看:

    ......

    ?

    System configuration file name: /etc/msmtprc

    User configuration file name: /root/.msmtprc

    显然要保证有/etc/msmtprc文件并要设置好它的配置内容。我的/etc/msmtprc内容如下:

    # Set default values for all following accounts.

    defaults


    logfile /usr/local/msmtp/msmtp.log

    # The SMTP server of the provider.

    account test


    # SMTP邮件服务器地址

    host smtp.ym.163.com


    # 发送的邮件Email

    from [email protected]

    auth login


    # 邮件服务器登录账号

    user [email protected]

    # 邮件服务器登陆密码

    password 12345678

    # Set a default account

    account default : test


    不过,我打开上面的测试php时,开始时出来Error. Please check error log.

    发送邮件不成功,查看apache的error_log, 找到错误信息:

    msmtp: /etc/msmtprc: must be owned by you


    原来是/etc/msmtprc的权限是777的话也不行,需要限制。 ps aux|grep httpd查看apache的进程的用户名是www,

    然后:

    chown www.www /etc/msmtprc

    chmod 600 /etc/msmtprc # 一定要600而不是777 !

    搞定!
    然后在mantis里配置?$g_phpMailer_method ? ? ? ? ? ? = PHPMAILER_METHOD_MAIL
    这样比配置 PHPMAILER_METHOD_SMTP 发邮件要快得多,都可立即收到邮件!

    ?

    ?

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PHP 框架性能比较:速度与效率的终极对决 PHP 框架性能比较:速度与效率的终极对决 Apr 30, 2024 pm 12:27 PM

根据基准测试,Laravel在页面加载速度和数据库查询方面表现出色,而CodeIgniter在数据处理方面表现优异。选择PHP框架时,应考虑应用程序规模、流量模式和开发团队技能。

Java 并发编程中如何进行并发测试和调试? Java 并发编程中如何进行并发测试和调试? May 09, 2024 am 09:33 AM

并发测试和调试Java并发编程中的并发测试和调试至关重要,以下技术可供使用:并发测试:单元测试:隔离并测试单个并发任务。集成测试:测试多个并发任务之间的交互。负载测试:评估应用程序在高负载下的性能和可扩展性。并发调试:断点:暂停线程执行并检查变量或执行代码。日志记录:记录线程事件和状态。堆栈跟踪:识别异常源头。可视化工具:监视线程活动和资源使用情况。

evasive 模块保护您的网站免受应用层 DOS 攻击 evasive 模块保护您的网站免受应用层 DOS 攻击 Apr 30, 2024 pm 05:34 PM

有多种可以导致网站下线的攻击方法,比较复杂的方法要涉及数据库和编程方面的技术知识。一个更简单的方法被称为“拒绝服务DenialOfService”(DOS)攻击。这个攻击方法的名字来源于它的意图:使普通客户或网站访问者的正常服务请求被拒绝。一般来说,有两种形式的DOS攻击:OSI模型的三、四层,即网络层攻击OSI模型的七层,即应用层攻击第一种类型的DOS攻击——网络层,发生于当大量的垃圾流量流向网页服务器时。当垃圾流量超过网络的处理能力时,网站就会宕机。第二种类型的DOS攻击是在应用层,是利用合

eclipse如何添加服务器 eclipse如何添加服务器 May 05, 2024 pm 07:27 PM

要将服务器添加到 Eclipse,请执行以下步骤:创建服务器运行时环境配置服务器创建服务器实例选择服务器运行时环境配置服务器实例启动服务器部署项目

算法在 58 画像平台建设中的应用 算法在 58 画像平台建设中的应用 May 09, 2024 am 09:01 AM

一、58画像平台建设背景首先和大家分享下58画像平台的建设背景。1.传统的画像平台传统的思路已经不够,建设用户画像平台依赖数据仓库建模能力,整合多业务线数据,构建准确的用户画像;还需要数据挖掘,理解用户行为、兴趣和需求,提供算法侧的能力;最后,还需要具备数据平台能力,高效存储、查询和共享用户画像数据,提供画像服务。业务自建画像平台和中台类型画像平台主要区别在于,业务自建画像平台服务单条业务线,按需定制;中台平台服务多条业务线,建模复杂,提供更为通用的能力。2.58中台画像建设的背景58的用户画像

如何使用 PHP 部署和维护网站 如何使用 PHP 部署和维护网站 May 03, 2024 am 08:54 AM

要成功部署和维护PHP网站,需要执行以下步骤:选择Web服务器(如Apache或Nginx)安装PHP创建数据库并连接PHP上传代码到服务器设置域名和DNS监控网站维护步骤包括更新PHP和Web服务器、备份网站、监控错误日志和更新内容。

如何使用 Fail2Ban 保护服务器免受暴力攻击 如何使用 Fail2Ban 保护服务器免受暴力攻击 Apr 27, 2024 am 08:34 AM

Linux管理员的一个重要任务是保护服务器免受非法攻击或访问。默认情况下,Linux系统带有配置良好的防火墙,比如iptables、UncomplicatedFirewall(UFW),ConfigServerSecurityFirewall(CSF)等,可以防止多种攻击。任何连接到互联网的机器都是恶意攻击的潜在目标。有一个名为Fail2Ban的工具可用来缓解服务器上的非法访问。什么是Fail2Ban?Fail2Ban[1]是一款入侵防御软件,可以保护服务器免受暴力攻击。它是用Python编程语

如何实施 PHP 安全最佳实践 如何实施 PHP 安全最佳实践 May 05, 2024 am 10:51 AM

如何实施PHP安全最佳实践PHP是最受欢迎的后端Web编程语言之一,用于创建动态和交互式网站。然而,PHP代码可能容易受到各种安全漏洞的攻击。实施安全最佳实践对于保护您的Web应用程序免受这些威胁至关重要。输入验证输入验证是验证用户输入并防止恶意输入(如SQL注入)的关键第一步。PHP提供了多种输入验证函数,例如filter_var()和preg_match()。示例:$username=filter_var($_POST['username'],FILTER_SANIT

See all articles