今天我爱编程网小编整理了PHP如何使用MAIL函数发邮件相关信息,希望在这方面能够更好帮助到大家。
本文目录一览:

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函数到底怎么配置
楼主用phpmailer吧,我用过,比较简单。下面是摘的一段phpmailer配置,试试看,有什么问题再提问。
第一,需要下载PHPMailer文件包phpmailer.
第二,确认你的服务器系统已经支持socket
,通过phpinfo();查看是否支持sockets(socket 是属于PHP扩展部分),如果显现为“enabled”,那就是支持了。
第三,把文件解压到你的web服务器目录下,调用类就可以了.
首先包含class.phpmailer.php,然后创建对象,设置参数,调用成员函数。具体请见下面的示例代码:
实例1,做成函数方便调用
<?php
require("phpmailer/class.phpmailer.php");
function smtp_mail( $sendto_email, $subject, $body, $extra_hdrs, $user_name){
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "200.162.244.66"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourmail"; // SMTP username 注意:普通邮件认证不需要加 @域名
$mail->Password = "mailPassword"; // SMTP password
$mail->From = "yourmail@yourdomain.com"; // 发件人邮箱
$mail->FromName = "管理员"; // 发件人
$mail->CharSet = "GB2312"; // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"username"); // 收件人邮箱和姓名
$mail->AddReplyTo("yourmail@yourdomain.com","yourdomain.com");
//$mail->WordWrap = 50; // set word wrap 换行字数
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
// 邮件主题
$mail->Subject = $subject;
// 邮件内容
$mail->Body = "
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>
I love php。
</body>
</html>
";
$mail->AltBody ="text/html";
if(!$mail->Send())
{
echo "邮件发送有误 <p>";
echo "邮件错误信息: " . $mail->ErrorInfo;
exit;
}
else {
echo "$user_name 邮件发送成功!<br />";
}
}
// 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名)
smtp_mail("yourmail@yourdomain.com", "欢迎使用phpmailer!", "NULL", "yourdomain.com", "username");
?>
要注意的内容:
1. 邮件的字符集设置,
$mail->CharSet = "GB2312"; //
这里指定字符集!在这里我只指定为GB2312因为这样Outlook能正常显示邮件主题,我尝试过设为utf-8但在Outlook下显示乱码。
2. 如果是发送html格式的邮件,那么记得也指定<meta ... charset=GB2312">
3. 如果你想用它来群发邮件的话,记得修改包含文件函数,如:
require("phpmailer/class.phpmailer.php");
改为
require_once("phpmailer/class.phpmailer.php");
否则的话会产生类的重定义。
我爱编程网
如何在Windows系统中安装sendmail使用PHP mail函数
我爱编程网(https://www.52biancheng.com)小编还为大家带来如何在Windows系统中安装sendmail使用PHP mail函数的相关内容。
php mail()函数在windows不能用,需要安装sendmail。
1.下载sendmail.zip
2.解压到C:下,例如C:\PHP\sendmail,最好短路径,长路径名有可能产生问题。
3.修改php.ini如下
sendmail_path = "C:\PHP\sendmail\sendmail.exe -t"
4.根据你自己的配置环境修改sendmail.ini。
第一次最好启用debug.log_file,error_logfile,以查看sendmail是否生效。
5.重启apache
用sendmail结合其它的smtp服务器,如smtp.gmail.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。
php.ini配置 (以用gmail邮箱为例)
[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25
; For Win32 only.
sendmail_from = zmacro@gmail.com
; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).
sendmail_path = “C:\PHP\sendmail\sendmail.exe -t”
就配置三项,smtp、smtp_port和sendmail_path
sendmail.ini配置
[sendmail]
; you must change mail.mydomain.com to your smtp server
smtp_server=smtp.gmail.com
smtp_port=25
auth_username=yourusername
auth_password=yourpassword
force_sender=zmacro@gmail.com
; default_domain=mydomain.com
sendmail网上有下的,如果你是用xampp,那里面直接就带了。
同时在虚拟主机的httpd.conf里加上这样一句
<directory d:/www/users/username> php_admin_value sendmail_path ‘C:\PHP\sendmail\sendmail.exe -t zmacro@gmail.com’</directory>
此邮件地址为用户的邮件地址,随便添。
------------------------
测试文件mail_test.php
<?
if(mail("yourname@sina.com","测试","测试邮件"))
{
echo "发送成功!!";
}
else{
echo "发送失败!!";
}
?>
以上,就是我爱编程网小编给大家带来的PHP如何使用MAIL函数发邮件全部内容,希望对大家有所帮助!更多相关文章关注我爱编程网:
www.52biancheng.com免责声明:文章内容来自网络,如有侵权请及时联系删除。