Home >Backend Development >PHP Tutorial >php发送注册邮件,邮件收到后变纯html文本了
代码如下:
}
else
{
if (isset($_POST['n_register']))
{
$mail = trim($db->EscapeString($_POST['reg_mail']));
$mail_re = trim($db->EscapeString($_POST['reg_mail_re']));
if (!preg_match("/^[a-zA-Z_\\-][\\w\\.\\-_]*[a-zA-Z0-9_\\-]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$/i", $mail))
{
$errorMsg = $langBase->get('home-08');
}
elseif ($mail !== $mail_re)
{
$errorMsg = $langBase->get('home-09');
}
elseif ($db->GetNumRows($db->Query("SELECT id FROM `[users]` WHERE `email`='".$mail."' LIMIT 1")) > 0)
{
$errorMsg = $langBase->get('home-10');
}
elseif ($db->GetNumRows($db->Query("SELECT id FROM `[users]` WHERE `IP_regged_with`='".$_SERVER['REMOTE_ADDR']."' LIMIT 1")) > 0)
{
$errorMsg = $langBase->get('home-11');
}
elseif ($db->GetNumRows($db->Query("SELECT id FROM `temporary` WHERE `playerid`='".$mail."' AND `active`='1' AND `area`='register' AND `time_added`+`expires`>'".time()."' LIMIT 1")) > 0)
{
$errorMsg = $langBase->get('home-111');
}
elseif (!isset($_POST['acc_tos']))
{
$errorMsg = $langBase->get('home-12');
}
else
{
$extra = array(
'mail' => $mail,
'enlist' => isset($_GET['e']) ? $db->EscapeString($_GET['e']) : $ref_id
);
$enlist_id = isset($_GET['e']) ? $db->EscapeString($_GET['e']) : $ref_id;
$tempID = substr(sha1(uniqid(rand())), 0, 6);
$db->Query("INSERT INTO `temporary` (`id`, `playerid`, `area`, `expires`, `time_added`, `extra`)VALUES('".$tempID."', '".$mail."', 'register', '3600', '".time()."', '".serialize($extra)."')");
mail($mail, $admin_config['game_name']['value'].' ?Signup',
'
'.$admin_config['game_name']['value'].'« Signup |
Hello, Click bellow to go at step 2: '.$config['base_url'].'?side=signup&step=2&v='.$tempID.' This link is active until '.View::Time(time()+3600, true).'. |
Best Regards, '.$admin_config['game_name']['value'].' |
单独打印html文本,看看是否可以解析。
邮箱不支持html??
邮箱不支持html??
给你一个发邮件函数吧
function send_mail($to, $subject = 'No subject', $body) {
$loc_host = "mail.server"; //发信计算机名,可随意
$smtp_acc = "test@163.com"; //发邮件邮箱
$smtp_pass="111"; //密码
$smtp_host="ssl.corp-email.com"; //邮件服务器
$from="test@163.com"; //发邮件邮箱
$deliver=$smtp_acc;
$headers = "Content-Type: text/plain; charset=\"gb2312\"\r\nContent-Transfer-Encoding: base64";
$lb="\r\n";
$hdr = explode($lb,$headers);
if($body) {$bdy = preg_replace("/^\./","..",explode($lb,$body));}
$smtp = array(
array("EHLO ".$loc_host.$lb,"220,250","HELO error: "),
array("AUTH LOGIN".$lb,"334","AUTH error:"),
array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "),
array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : "));
$smtp[] = array("MAIL FROM: ".$lb,"250","MAIL FROM error: ");
$smtp[] = array("RCPT TO: ".$lb,"250","RCPT TO error: ");
$smtp[] = array("DATA".$lb,"354","DATA error: ");
$smtp[] = array("From: ".$deliver.$lb,"","");
$smtp[] = array("To: ".$to.$lb,"","");
$smtp[] = array("Subject: ".$subject.$lb,"","");
foreach($hdr as $h) {$smtp[] = array($h.$lb,"","");}
$smtp[] = array($lb,"","");
if($bdy) {foreach($bdy as $b) {$smtp[] = array(base64_encode($b.$lb).$lb,"","");}}
$smtp[] = array(".".$lb,"250","DATA(end)error: ");
$smtp[] = array("QUIT".$lb,"221","QUIT error: ");
$fp = @fsockopen($smtp_host, 25);
if (!$fp) echo "Error: Cannot conect to ".$smtp_host."
";
while($result = @fgets($fp, 1024)){if(substr($result,3,1) == " ") { break; }}
$result_str="";
foreach($smtp as $req){
@fputs($fp, $req[0]);
if($req[1]){
while($result = @fgets($fp, 1024)){
if(substr($result,3,1) == " ") { break; }
};
if (!strstr($req[1],substr($result,0,3))){
$result_str.=$req[2].$result."
";
}
}
}
@fclose($fp);
return $result_str;
};
?>