如果需要用php的mail()函数来发送邮件,是需要服务器安装sendmail组件才能支持的,这个在php的手册中mail()函数部分也有介绍到.在Ubuntu下安装sendmail的命令:sudo apt-get install sendmail安装好之后,启动sendmail服务:sudo service sendmail start有了sendmail的支持,就可以在php中用mail()函数发送邮件了.
function?sendMail($to,?$title,?$content)?{
Vendor('PHPMailer.PHPMailerAutoload');
$mail?=?new?PHPMailer();?//实例化
$mail-IsSMTP();?//?启用SMTP
$mail-Host=C('MAIL_HOST');?//smtp服务器的名称(这里以QQ邮箱为例)
$mail-SMTPAuth?=?C('MAIL_SMTPAUTH');?//启用smtp认证
$mail-Username?=?C('MAIL_USERNAME');?//你的邮箱名
$mail-Password?=?C('MAIL_PASSWORD')?;?//邮箱密码
$mail-From?=?C('MAIL_FROM');?//发件人地址(也就是你的邮箱地址)
$mail-FromName?=?C('MAIL_FROMNAME');?//发件人姓名
$mail-AddAddress($to,"尊敬的客户");
$mail-IsHTML(C('MAIL_ISHTML'));?//?是否HTML格式邮件
$mail-CharSet=C('MAIL_CHARSET');?//设置邮件编码
$mail-Subject?=$title;?//邮件主题
$mail-Body?=?$content;?//邮件内容
$mail-AltBody?=?"";?//邮件正文不支持HTML的备用显示
$relt?=?$mail-Send();
if(!$relt)?{
writeLog('发送邮件错误,错误信息:'.?$mail-ErrorInfo,?1,?'发送邮箱失败');
}
return($relt);
这个是thinkphp版本的.
有两种方法
第一段:使用PHP内置的mail()函数
第二段:使用封装SMTP协议的邮件类
具体可以参考这篇文章,希望对你有帮助
PHP mail 发送邮件
mail — 发送邮件
说明
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
发送一封电子邮件.
参数
to
电子邮件收件人,或收件人列表.
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
所要发送的消息.
(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用phpmail写邮件,php相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!