導航:首頁 > 編程語言 > phphtml格式郵件

phphtml格式郵件

發布時間:2022-05-23 16:41:02

A. 如何使用php中的mail函數發送html格式的信

採用phpmailer類,來做郵件發送,是很多PHP程序所採用的一個類發送
require(ROOT.'/class/phpMailer.class.php');//郵件發送類
/**
*發送郵件
*@paramstring$to接收人郵件地址
*@paramstring$title郵件標題
*@paramstring$contents郵件內容支持HTML格式
*@paramstring$type判斷是否要加附件
*@paramstring$accessory附件的名字
*@return成功返回true,失敗返回錯誤信息
*/
functionsendEmail($to,$title,$contents,$type='',$accessory=''){
$mail=newPhpMailer(true);
$mail->IsSMTP();
$mail->CharSet="UTF-8";//編碼
$mail->Debugoutput='html';//支持HTML格式
$mail->Host=T_SMTP_SERVER;//HOST地址
$mail->Port=25;//埠
$mail->SMTPAuth=true;
$mail->Username=T_SMTP_LOGIN;//用戶名
$mail->Password=T_SMTP_PASSWORD;//密碼
$mail->SetFrom(T_SMTP_FROM,T_SMTP_FROM_NAME);//發件人地址,發件人名稱
$mail->AddAddress($to);//收信人地址
//$mail->Subject="=?utf-8?B?".base64_encode()."?=";
if(!empty($type)){
$mail->AddAttachment($type,$accessory);//添加附件,並指定名稱
}
$mail->Subject=$title;//郵件標題
$mail->MsgHTML($contents);
if($mail->Send()){
returntrue;
}else{
return$mail->errorMessage();
}
}

B. php能夠發送html格式的郵件,郵件伺服器能夠解析,該怎麼做

用普通的html代碼就可以,我用PHPMailer,裡面有個IsHTML()的方法,標明發送內容為html格式,郵件自然會解析為html格式,根據你使用發送郵件的東西,應該會有個設置發送格式,你可以找找看

C. 如何用php把提取到的html表單發郵件到指定郵箱

<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(); //實例化
$mail->IsSMTP(); // 啟用SMTP
$mail->Host = "smtp.qq.com"; //SMTP伺服器 以163郵箱為例子
$mail->Port = 25; //郵件發送埠
$mail->SMTPAuth = true; //啟用SMTP認證

$mail->CharSet = "UTF-8"; //字元集
$mail->Encoding = "base64"; //編碼方式

$mail->Username = "[email protected]"; //你的郵箱
$mail->Password = "XXXX"; //你的密碼
$mail->Subject = "你好"; //郵件標題

$mail->From = "[email protected]"; //發件人地址(也就是你的郵箱)
$mail->FromName = "久飛WEB"; //發件人姓名

$address = "[email protected]";//收件人email
$mail->AddAddress($address, "親");//添加收件人(地址,昵稱)

// 添加附件,並指定名稱

$mail->IsHTML(true); //支持html格式內容
$mail->Body = '你好, <b>朋友</b>! <br/>這是一封來自<a href="http://www.jiufei.cc" target="_blank">jiufei.cc</a>的郵件!<br/>';

//發送
if(!$mail->Send()) {
echo "發送失敗: " . $mail->ErrorInfo;
} else {
$_SESSION['ip'] = get_client_ip();
$_SESSION['time'] = time();
echo "1";
}

function get_client_ip() {
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else
if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return ($ip);
}

?>

D. 我想用php發郵件,我想發html格式的,body應該怎麼寫呢,要發的文件是D:\local\website\proj\test\123.htm

你看看這個行么??
<?php
/**
*一個很簡單的提交留言到指定郵箱的類。
*/
//發送郵件的類
class Smtp
{

/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* Private Variables */
var $sock;
/* Constractor */

function Smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()

#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;

#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";

$this->sock = FALSE;
}

/* Main Function */

function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{

$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header = "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}

if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);

if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
} else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}

if (!$this->smtp_message($header, $body)) {

return $this->smtp_error("sending message");

}

if (!$this->smtp_eom()) {

return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");

}

if (!$this->smtp_putcmd("QUIT")) {

return $this->smtp_error("sending QUIT command");

}

return TRUE;

}

function smtp_sockopen($address)

{

if ($this->relay_host == "") {

return $this->smtp_sockopen_mx($address);

} else {
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug) {
echo $message;
}
}
}

/********************************************************************************************/
//本類是針對qq的,如果你的qq有限沒有開啟stmp服務,請開啟。
$smtpserver = "smtp.qq.com"; //SMTP伺服器
$smtpserverport =25; //SMTP伺服器埠
$smtpusermail = "你的QQ號碼@qq.com"; //SMTP伺服器的用戶郵箱
$smtpemailto = "[email protected]"; //發送給誰
$smtpuser = "你的qq號碼@qq.com"; //SMTP伺服器的用戶帳號
$smtppass = "你的qq密碼"; //SMTP伺服器的用戶密碼 這里是指你qq的密碼
$mailsubject = "測試郵件主題"; //郵件主題
$mailbody = "<h1>測試郵件的內容...............................................</h1>"; //郵件內容
$mailtype = "HTML"; //郵件格式(HTML/TXT),TXT為文本郵件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass); //這裡面的一個true是表示使用身份驗證,否則不使用身份驗證.
$smtp->debug = false; //是否顯示發送的調試信息
if($smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype)=="1"){
echo "郵件發送成功!";
}else{
echo "郵件發送失敗!";
}

?>

E. php發送郵件如何解析html

$mailstr.="Content-Type:text/html;charset=utf-8
";

郵件內容開始時候加上content-type.

charset 改為你指定的編碼

F. php的mail怎麼發html格式的郵件

可以採用 phpmailer類,來做郵件發送,這也是很多PHP程序所採用的一個類發送

require(ROOT.'/class/phpMailer.class.php');//郵件發送類
/**
* 發送郵件
* @param string $to 接收人郵件地址
* @param string $title 郵件標題
* @param string $contents 郵件內容 支持HTML格式
* @param string $type 判斷是否要加附件
* @param string $accessory 附件的名字
* @return 成功返回true,失敗返回錯誤信息
*/
function sendEmail($to,$title,$contents,$type = '',$accessory =''){
$mail = new PhpMailer(true);
$mail->IsSMTP();
$mail->CharSet ="UTF-8";//編碼
$mail->Debugoutput = 'html';// 支持HTML格式
$mail->Host = T_SMTP_SERVER;//HOST 地址
$mail->Port = 25;//埠
$mail->SMTPAuth = true;
$mail->Username = T_SMTP_LOGIN;//用戶名
$mail->Password = T_SMTP_PASSWORD;//密碼
$mail->SetFrom(T_SMTP_FROM,T_SMTP_FROM_NAME);//發件人地址, 發件人名稱
$mail->AddAddress($to);//收信人地址
//$mail->Subject = "=?utf-8?B?" . base64_encode() . "?=";
if (!empty($type)) {
$mail->AddAttachment($type,$accessory); // 添加附件,並指定名稱
}
$mail->Subject = $title;//郵件標題
$mail->MsgHTML($contents);
if ($mail->Send()){
return true;
}else{
return $mail->errorMessage();
}
}
望採納 Thx

G. 怎樣利用php把html表單的全部信息發送郵件

$mailbody =$_POST;
你把$_POST賦給了郵件內容,而$_POST本來就是一個數組 所以會顯示是Array
改成:$mailbody =$_POST["name"]."\n".$_POST['add']."\n".$_POST['c']."\n".$_POST['d'];
試試看?

H. phplist系統發送html格式的郵件,卻把html格式里的文字和超鏈接都提取並顯示出來,為什麼會出現這

html源文件里超文本引用(hypertext reference)也叫超鏈接都是有特殊的標簽的有不有。
舉個例子:href="http://..com/question/158971081.html" 格式都是這樣的有木有。
你可以在網頁空白處右擊選擇 查看源文件 然後自己看看每個超鏈接都是上面的格式有木有。
如果要自己寫java程序的話,建議
1.先讀取一個html的源文件
2.然後用上面朋友的建議,用正規表達式來識別。
也可以自己找專門的html分析工具哦。

閱讀全文

與phphtml格式郵件相關的資料

熱點內容
台達PLC編譯按鈕在哪裡 瀏覽:137
非編程計算器多少錢 瀏覽:653
房本還完貸款解壓 瀏覽:816
中國程序員有出名嗎 瀏覽:546
亳州雲伺服器 瀏覽:630
程序員最難的面試 瀏覽:892
配音秀app怎麼誦讀 瀏覽:750
sparkcore源碼 瀏覽:100
程序員中年生活 瀏覽:355
讀取加密信息失敗怎麼回事 瀏覽:510
編譯過程之後是預處理嗎 瀏覽:351
安卓是基於什麼做出來 瀏覽:600
視頻字幕提取APP怎麼使用 瀏覽:59
js通過ip地址連接伺服器嗎 瀏覽:848
java數字金額大寫金額 瀏覽:858
人人影視路由器固件編譯 瀏覽:967
照片通訊錄簡訊怎麼從安卓到蘋果 瀏覽:458
邏輯開發編譯環境 瀏覽:672
ce自己編譯 瀏覽:898
javaexe進程 瀏覽:478