一 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格式
<?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']);
?>