首页 > 编程知识 正文

php的mail函数(php邮箱发送)

时间:2023-12-11 12:29:18 阅读:314306 作者:REQM

本文目录一览:

PHP如何使用MAIL函数发邮件

PHP mail 发送邮件

mail

(PHP 4, PHP 5)

mail — 发送邮件

说明

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

发送一封电子邮件。

参数

to

电子邮件收件人,或收件人列表。

本字符串的格式必须符合 » RFC 2822。例如:

user@example.com

user@example.com, anotheruser@example.com

User user@example.com

User user@example.com, Another User anotheruser@example.com

subject

电子邮件的主题。

Caution

本项不能包含任何换行符,否则邮件可能无法正确发送。

message

所要发送的消息。

行之间必须以一个 LF( )分隔。每行不能超过 70 个字符。

Caution

(Windows 下)当 PHP 直接连接到 SMTP 服务器时,如果在一行开头发现一个句号,则会被删掉。要避免此问题,将单个句号替换成两个句号。 ?php

$text = str_replace(" .", " ..", $text);

?

additional_headers(可选项)

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF ( ).

如何使用php的mail函数发送邮件

如果需要用php的mail()函数来发送邮件,是需要服务器安装sendmail组件才能支持的,这个在php的手册中mail()函数部分也有介绍到。在Ubuntu下安装sendmail的命令:sudo apt-get install sendmail安装好之后,启动sendmail服务:sudo service sendmail start有了sendmail的支持,就可以在php中用mail()函数发送邮件了。

如何使用php中的mail函数发送html格式的信

采用 phpmailer类,来做邮件发送,是很多PHP程序所采用的一个类发送

require(ROOT.'/class/phpMailer.class.php');//邮件发送类

/**

* 发送邮件

* @param string $to 接收人邮件地址

* @param string $title 邮件标题

* @param string $contents 邮件内容 支持HTML格式

* @param string $type 判断是否要加附件

* @param string $accessory 附件的名字

* @return 成功返回true,失败返回错误信息

*/

function sendEmail($to,$title,$contents,$type = '',$accessory =''){

$mail = new PhpMailer(true);

$mail-IsSMTP();

$mail-CharSet ="UTF-8";//编码

$mail-Debugoutput = 'html';// 支持HTML格式

$mail-Host = T_SMTP_SERVER;//HOST 地址

$mail-Port = 25;//端口

$mail-SMTPAuth = true;

$mail-Username = T_SMTP_LOGIN;//用户名

$mail-Password = T_SMTP_PASSWORD;//密码

$mail-SetFrom(T_SMTP_FROM,T_SMTP_FROM_NAME);//发件人地址, 发件人名称

$mail-AddAddress($to);//收信人地址

//$mail-Subject = "=?utf-8?B?" . base64_encode() . "?=";

if (!empty($type)) {

$mail-AddAttachment($type,$accessory); // 添加附件,并指定名称

}

$mail-Subject = $title;//邮件标题

$mail-MsgHTML($contents);

if ($mail-Send()){

return true;

}else{

return $mail-errorMessage();

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。