下面是用php 发送html Email。 开发平台: ubuntu. 开发环境: Php 5.2.3 Eclipse 3.5 + Xdebug
[b][color=darkblue]1 .需要安装的:[/color][/b]
[list]
[*]postfix
[*]curl for php
[/list]
[b][color=darkblue]2 .Html Ad设计:[/color][/b]
[list]
[*] [color=darkblue]css与Email client的兼容问题: Reference: http://www.campaignmonitor.com/css/[/color]
[*] [color=darkblue]页面设计的两个要点:[/color]
[/list]
[list]
[*][color=indigo]在html Email能够有这样的链接: "If you cannot read this page properly, please click here",用户点击这个链接就可以直接访问到该URL.[/color]
[*][color=indigo]有welcome Information.[/color]
[/list]
[b][color=darkblue]3 .发送Email:[/color][/b]
[b][color=darkblue]4. 测试和应用:[/color][/b]
wget -q "http://192.168.199.3/ajax/newsletter/customerdirectemail.php?uucustomerid=101" -O -; echo ""; sleep 1
[b][color=darkblue]1 .需要安装的:[/color][/b]
[list]
[*]postfix
[*]curl for php
[/list]
[b][color=darkblue]2 .Html Ad设计:[/color][/b]
[list]
[*] [color=darkblue]css与Email client的兼容问题: Reference: http://www.campaignmonitor.com/css/[/color]
[*] [color=darkblue]页面设计的两个要点:[/color]
[/list]
[list]
[*][color=indigo]在html Email能够有这样的链接: "If you cannot read this page properly, please click here",用户点击这个链接就可以直接访问到该URL.[/color]
[*][color=indigo]有welcome Information.[/color]
[/list]
<?php if ( isset( $mail ) && $mail == "yes" ) { ?>
<td align="right"><a href="<?php echo $current_url; ?>" target="_blank" class="a1"><?php echo "If you cannot read this page properly, please click here" ; ?></a>;</td>
<?php } else { ?>
<td align="right"><?php include ("languageselector.php")?></td>
<?php } ?>
[b][color=darkblue]3 .发送Email:[/color][/b]
<?php
require_once("CommonDefn.php");
require_once("DataService.php");
include( "Curl.php"); //这是一个封装了curl的Class,已在附件中
function encodeMIMEString ($enc, $string) {
return "=?$enc?B?" . base64_encode($string) . "?=";
}
$encoding = "UTF-8";
$customerid = $_REQUEST[Token::$WEB_CUSTOMERID_TOKEN];
$_REQUEST[Token::$WEB_MAIL_TOKEN] = "yes";
if ( ! isset( $ds ) ) {
$ds = new DataService();
}
$custobj = $ds->getCustomerInfo($customerid);
if ( isset( $custobj ) ) {
// $_REQUEST["ac"] = $custobj->activationcode;
// $_REQUEST["v"] = $edmversion;
if ( $custobj->preferredlanguageid == 1 ) {
$_REQUEST["lang"] = "zh";
$_REQUEST["cty"] = "tw";
} else if ( $custobj->preferredlanguageid == 2 ) {
$_REQUEST["lang"] = "zh";
$_REQUEST["cty"] = "cn";
} else {
$_REQUEST["lang"] = "en";
$_REQUEST["cty"] = "us";
}
//include("edm." . $edmversion . ".php");
include("template/subject.php");
$mime_boundary = "----" . md5(time()) . "----";
$to = $custobj->firstname . " <" . $custobj->primaryemail . ">";
$from = "donotreply@xxx.hk";
$mailsubject = encodeMIMEString($encoding, $subject);
$headers = "From: XXX Customer Service <" . $from . ">\n";
$headers .= "Reply-To: XXX Customer Service <" . $from . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"" . $mime_boundary . "\"\n";
$mailbody .= "--" . $mime_boundary . "\n";
$mailbody .= "Content-Type: text/html; charset=" . $encoding . "\n";
$mailbody .= "Content-Transfer-Encoding: 8bit\n\n";
//$mailbody .= $body;
// FINAL BOUNDARY
$curl= new cURL();
$servletpath = dirname( $_SERVER[PHP_SELF] );
$servername = $_SERVER[SERVER_NAME];
$destURL = "http://" . $servername . $servletpath . "/newsletter.php";
$fields =Token::$WEB_MAIL_TOKEN ."=yes" ;
$fields .= "&" . Token::$WEB_CUSTOMERID_TOKEN . "=" . $customerid . "&" ;
foreach($_REQUEST as $key => $value){
if(is_string($value)) {
$fields .= ($key . "=" . urlencode($value) . "&");
}
else if(is_array($value)) {
foreach($value as $single) {
$fields .= ($key . "[]=" . urlencode($single) . "&");
}
}
}
$postData = $fields;
$mailbody .= $curl->post($destURL,$postData);
$mailbody .= "--" . $mime_boundary . "--\n\n";
// SEND MAIL
$mail_sent = @mail( $to, $mailsubject, $mailbody, $headers );
if ( $mail_sent ) {
echo $to . " OK";
} else {
echo $to . " Fail";
}
} else {
echo "CustomerID " . $customerid . " is not found.";
}
?>
[b][color=darkblue]4. 测试和应用:[/color][/b]
wget -q "http://192.168.199.3/ajax/newsletter/customerdirectemail.php?uucustomerid=101" -O -; echo ""; sleep 1