PHP PEAR MAIL发送TEXT/HTML格式邮件
2005-02-21 13:54
811 查看
一 TEXT格式
邮件发送方式有3种
* mail
If safe mode is disabled, $params will be passed as the fifth argument to the PHP mail()
function. If $params is an array, its elements will be joined as a space-delimited string.
* sendmail
$params["sendmail_path"] - The location of the sendmail program on the filesystem.
Default is /usr/bin/sendmail
$params["sendmail_args"] - Additional parameters to pass to the sendmail program.
* smtp
$params["host"] - The server to connect. Default is localhost
$params["port"] - The port to connect. Default is 25
$params["auth"] - Whether or not to use SMTP authentication. Default is FALSE
$params["username"] - The username to use for SMTP authentication.
$params["password"] - The password to use for SMTP authentication.
<?php
require_once('Mail/Mail.php');
$recipients = '111@111.com';
$headers['From'] = '111@111.com';
$headers['To'] = '111@111.com';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params['username'] = '111@111.com';
$params['password'] = '111';
$params['auth'] = true;
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('mail', $params);
$mail_object->send($recipients, $headers, $body);
?>
二 HTML格式
邮件发送方式有3种
If safe mode is disabled, $params will be passed as the fifth argument to the PHP mail()
function. If $params is an array, its elements will be joined as a space-delimited string.
* sendmail
$params["sendmail_path"] - The location of the sendmail program on the filesystem.
Default is /usr/bin/sendmail
$params["sendmail_args"] - Additional parameters to pass to the sendmail program.
* smtp
$params["host"] - The server to connect. Default is localhost
$params["port"] - The port to connect. Default is 25
$params["auth"] - Whether or not to use SMTP authentication. Default is FALSE
$params["username"] - The username to use for SMTP authentication.
$params["password"] - The password to use for SMTP authentication.
<?php
require_once('Mail/Mail.php');
$recipients = '111@111.com';
$headers['From'] = '111@111.com';
$headers['To'] = '111@111.com';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params['username'] = '111@111.com';
$params['password'] = '111';
$params['auth'] = true;
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('mail', $params);
$mail_object->send($recipients, $headers, $body);
?>
二 HTML格式
<?php include('Mail.php'); include('Mail/mime.php'); $text = 'This is a Christmas email from www.omni-batteies.com.'; $html = '<html><body><h3><font color=red>This is a Christmas email from www.omni-batteies.com.</font></h3></body></html>'; $file = 'Special_Offer_For_Christmas.htm'; $crlf = "/n"; $hdrs = array( 'From' => '111@111.com', 'To' => 'Merry Christmas', 'Subject' => 'Christmas Message from www.omni-batteies.com' ); $mime = new Mail_mime(); $mime->setTXTBody($text); $mime->setHTMLBody($file, true); $mime->addAttachment($file, 'text/html'); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $params['host'] = 'mail.111.com'; $params['auth'] = true; $params['username'] = '111@111.com'; $params['password'] = '111'; $recipients = array('111@111.com', '222@111.com'); $send = @$mail =& Mail::factory('smtp', $params); $mail->send($recipients, $hdrs, $body); if(PEAR::isError($send)) { echo($send->getMessage()); } else { echo("send successfully"); } show_source($_SERVER['PHP_SELF']); ?>
相关文章推荐
- linux/window配置php PEAR:Mail发送html邮件
- 使用linux的mail命令发送html格式的邮件
- 使用linux的mail命令发送html格式的邮件
- php发送邮件 可发html格式邮件 附件
- php使用pear mail发送邮件
- Python网络编程:E-mail服务(九) 发送HTML格式邮件
- PHP的mail()函数发送邮件,其中的html标签未被正常解析的问题
- 介绍使用php发送邮件类(html格式及附件)
- MailKit/MimeKit 发送邮件时如何保持正文格式不变?MailKit/MimeKit HTml文本
- 利用sendmail命令发送html格式邮件
- sendmail-MIMEText.py――发送HTML格式的报表
- Windows下python发送邮件_CustomEmail.py[text、html、附件、读取文本到正文]
- python练习--发送html格式邮件且发送附件;
- 在Linux命令行下发送html格式的邮件
- SMTP邮件格式、SMTP 协议,SMTP的MIME写法,SMTP发送HTML邮件
- jenkins html 发送邮件格式
- 使用Pear和php socket来实现通过smtp验证发送邮件
- MailBee.NET Objects发送电子邮件(SMTP)教程五:发送带有嵌入图片的网页和HTML邮件
- [SQL Server]发送HTML格式邮件
- 关于ASP。NET发送HTML格式的邮件