php mail()邮件发送配置方法
这两天写了个方法用到php mail()本以为php提供的这个方法非常简单、方便、易用,其实不然!
php mail()函数需要配置才可以发邮件的哦,下面配置方法:
如果你没有使用windows,那么sendmail_path指令就是你唯一要担心的东西.如果你正在使用Windows,你就需要看看最后两个指令.
如果你使用的是Linux或是一个Unix变种,sendmail_path看起来应该象这样:
sendmail_path = /usr/sbin/sendmail
或者如果你使用Qmail:
sendmail_path = /var/qmail/bin/sendmail
在PHP mail()函数中的这条指令里,你还可以设置配置参数来指明队列缓冲选项或是显示的设置Return-Path头,如下所示:
sendmail_path = /usr/sbin/sendmail -t -fyou@yourdomain.com
作为一个非Windows用户,这就是你要做的一切了.如果你使用的是Windows,你有更多的事情要做.你还需要看一看SMTP和sendmail_from的值.不要被sendmail_from指令名字中的sendmail弄迷糊了.虽然你没有在Windows上使用名叫Sendmail的程序,但那只是指令的名字.不要被它吓到了.
在你的phpinfo()显示的结果里,看看SMTP和sendmail_from的缺省值--它们要么是空白,要么包含了胡乱的值.你应该把它们改成有意义的值.
如果你决心在这台电脑上运行一个SMTP服务程序,你在php.ini文件中的条目就应该如下:SMTP = localhost
但是,如果你要使用你ISP(在这个例子中是EarthLink)的外发邮件服务器,那么php.ini中的邮件看起来应该如下:SMTP = mail.earthlink.net
你也可以使用IP地址而不是域名,因为计算机不区分这两种条目.
第二条配置指令是sendmail_from,它应该被设置成From头中的电子邮件地址.它可以在脚本里被修改但是通常作为缺省值使用.下面就是这个配置指令的示例youraddress@yourdomain.com指的是你自己的邮件地址,代码如下:
sendmail_from = youraddress@yourdomain.com
发送一个简单的电子邮件,代码如下:
$txt = "First line of textnSecond line of text"; // Use wordwrap() if lines are longer than 70 characters $txt = wordwrap($txt,70); // Send email mail("somebody@example.com","My subject",$txt);
刚开始感觉非常不错,网易邮箱、QQ邮箱、GMAIL邮箱常用的邮箱都可以收到,但经测试HOTMAIL、TOM、LIVE等邮箱是收不到此类邮件的!
经查询邮件发送的时候,一般都需要身份验证,而PHP自带的mail()无能为力,很脆弱啊!
永久链接:
转载随意!带上文章地址吧。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PyCharm is a powerful integrated development environment (IDE), and PyTorch is a popular open source framework in the field of deep learning. In the field of machine learning and deep learning, using PyCharm and PyTorch for development can greatly improve development efficiency and code quality. This article will introduce in detail how to install and configure PyTorch in PyCharm, and attach specific code examples to help readers better utilize the powerful functions of these two. Step 1: Install PyCharm and Python

Title: How to correctly configure Git in PyCharm In modern software development, the version control system is a very important tool, and Git, as one of the popular version control systems, provides developers with powerful functions and flexible operations. As a powerful Python integrated development environment, PyCharm comes with support for Git, allowing developers to manage code versions more conveniently. This article will introduce how to correctly configure Git in PyCharm to facilitate better development during the development process.

Title: The working principle and configuration method of GDM in Linux systems In Linux operating systems, GDM (GNOMEDisplayManager) is a common display manager used to control graphical user interface (GUI) login and user session management. This article will introduce the working principle and configuration method of GDM, as well as provide specific code examples. 1. Working principle of GDM GDM is the display manager in the GNOME desktop environment. It is responsible for starting the X server and providing the login interface. The user enters

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

How to configure a workgroup in Win11 A workgroup is a way to connect multiple computers in a local area network, which allows files, printers, and other resources to be shared between computers. In Win11 system, configuring a workgroup is very simple, just follow the steps below. Step 1: Open the "Settings" application. First, click the "Start" button of the Win11 system, and then select the "Settings" application in the pop-up menu. You can also use the shortcut "Win+I" to open "Settings". Step 2: Select "System" In the Settings app, you will see multiple options. Please click the "System" option to enter the system settings page. Step 3: Select "About" In the "System" settings page, you will see multiple sub-options. Please click

PyCharm is a commonly used integrated development environment (IDE). In daily development, using Git to manage code is essential. This article will introduce how to configure Git in PyCharm and use Git for code management, with specific code examples. Step 1: Install Git First, make sure Git is installed on your computer. If it is not installed, you can go to [Git official website](https://git-scm.com/) to download and install the latest version of Git

Title: How to configure and install FTPS in Linux system, specific code examples are required. In Linux system, FTPS is a secure file transfer protocol. Compared with FTP, FTPS encrypts the transmitted data through TLS/SSL protocol, which improves Security of data transmission. In this article, we will introduce how to configure and install FTPS in a Linux system and provide specific code examples. Step 1: Install vsftpd Open the terminal and enter the following command to install vsftpd: sudo

MyBatisGenerator is a code generation tool officially provided by MyBatis, which can help developers quickly generate JavaBeans, Mapper interfaces and XML mapping files that conform to the database table structure. In the process of using MyBatisGenerator for code generation, the setting of configuration parameters is crucial. This article will start from the perspective of configuration parameters and deeply explore the functions of MyBatisGenerator.
