當前位置:首頁 » 編程語言 » emailphp

emailphp

發布時間: 2022-09-24 14:08:39

⑴ 我發一封email,php程序實現監測email有沒有被查看可以做到嗎 以及思路

插入一個js或圖片,或是其它什麼這個要得自己想,然後要訪問的就是你的網站,然後來判斷是否有訪問,可以記錄用戶的cookies等信息,但要注意不要做非法的活動。

⑵ php如何在email中羅列產品

在php中地址驗證寫法各種各樣的,下面我來總結幾種常用的email地址驗證實例,最簡單的是直接使用正則表達式preg_match(\"/^([a-z0-9\\+_\\-]+)(\\.[a-z0-9\\+_\\-]+)*@([a-z0-9\\-]+\\.)+[a-z]{2,6}$/ix來驗證了。

PHP入門教程請戳這里:http://www.tiecou.com/1832.html

⑶ 怎麼利用php發送郵件求詳細教程

PHP雖然提供了mail()函數,但並不好用,而PHPMailer是一個不錯的郵件發送工具,接下來將詳細介紹,需要了解的朋友可以參考下:

本人使用wamp集成開發環境,Apache2.4.4, Mysql5.6.12 , php5.4.12.開始的時候使用mail()發送郵件,更改配置始終無法成功,了解到mail()函數使用需要sendmail程序。又下載了sendmail程序擴展包。按照網上的說法也改好了php.ini和sendmail.ini。使用foxmail 7.1創建了自己的qq郵箱賬戶,開啟了POP3/SMTP服務,更改發件伺服器為POP3,使用和收件伺服器相同的身份驗證,結果還是報錯:Warning: mail(): SMTP server response: 503 Error: need EHLO and AUTH first ! in F:\PHP\wamp\www\mail.php on line 8。以下是使用mail()函數發送郵件的php代碼:

[php] view plain
<span style="font-size:14px"><?php

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From: $from";
$send=mail($to,$subject,$message,$headers);
if($send)
echo "Mail Sent";
else
echo "Sorry,mail sent failed!"

?></span>
在CSDN論壇上發現phpmailer可以方便快捷的發送郵件,以下寫出詳細使用教程:
1.需要下載PHPMailer文件包,(點擊打開鏈接)

2.確認你的伺服器已經系統支持socket,通過phpinfo()查看是否支持socket;

3.把文件解壓到你的WEB伺服器目錄下,就可以使用PHPMailer發送郵件了。

以下為前台表單php代碼:

[php] view plain
<span style="font-size:14px"><html>
<body>
<h3>phpmailer Unit Test</h3>
請你輸入<font color="#FF6666">收信</font>的郵箱地址:
<form name="phpmailer" action="testemail.php" method="post">
<input type="hidden" name="submitted" value="1"/>
郵箱地址: <input type="text" size="50" name="to" />
<br/>
<input type="submit" value="發送"/>
</form>
</body>
</html> </span>
以下為後台程序:

[php] view plain
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/

header("content-type:text/html;charset=utf-8");

ini_set("magic_quotes_runtime",0);

require('class.phpmailer.php');

try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled

//$body = file_get_contents('contents.html');
//$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$to = $_POST['to'];
$mail->CharSet="GB2312";//設置郵件字元編碼否則郵件會亂碼
$mail->Encoding="base64";
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "smtp.qq.com"; // SMTP server
$mail->Username = "[email protected]"; // SMTP server username
$mail->Password = "000000000000"; // SMTP server password

//$mail->IsSendmail(); // tell the class to use Sendmail

$mail->AddReplyTo("[email protected]","han qing");

$mail->From = "[email protected]";
$mail->FromName = "han qing";

//$to = "[email protected]";

$mail->AddAddress($to);

$mail->Subject =$mail->Subject = "=?utf-8?B?" . base64_encode("First PHPMailer Message") . "?=";

$mail->Body = "<h1>phpmailer演示</h1> 這是用PHPMAILER發的第一份郵件,從QQ郵箱發到Google郵箱.";

$mail->AddAttachment("F:/myloe.jpg");

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap

//$mail->MsgHTML($body);

$mail->IsHTML(true); // send as HTML

$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>

⑷ 使用php 怎麼發送郵件

你這個是連接的郵件伺服器出錯了。
估計你本地應該沒有裝郵件伺服器吧,一般都會用第三方的郵件伺服器,如smtp.163.com,
去下載個phpmailer,從裡面把class.phpmailer.php提取出來,用很好用的。

⑸ PHP 能用自帶的email函數發兩封郵件么

可以在php上配置一個PEAR,裡面有Mail.php這個庫,通過這個庫文件就可以發送郵件了。

⑹ php編程---email功能

*/
set_time_limit(120);
class smtp_mail
{
var $host; //主機
var $port; //埠 一般為25
var $user; //SMTP認證的帳號
var $pass; //認證密碼
var $debug = false; //是否顯示和伺服器會話信息?
var $conn;
var $result_str; //結果
var $in; //客戶機發送的命令
var $from; //源信箱
var $to; //目標信箱
var $subject; //主題
var $body; //內容
function smtp_mail($host,$port,$user,$pass,$debug=false)
{
$this->host = $host;
$this->port = $port;
$this->user = base64_encode($user);
$this->pass = base64_encode($pass);
$this->debug = $debug;
$this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); //具體用法請參考手冊
if($this->socket)
{
$this->result_str = "創建SOCKET:".socket_strerror(socket_last_error());
$this->debug_show($this->result_str);
}
else
{
exit("初始化失敗,請檢查您的網路連接和參數");
}
$this->conn = socket_connect($this->socket,$this->host,$this->port);
if($this->conn)
{
$this->result_str = "創建SOCKET連接:".socket_strerror(socket_last_error());
$this->debug_show($this->result_str);
}
else
{
exit("初始化失敗,請檢查您的網路連接和參數");
}
$this->result_str = "伺服器應答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);

}
function debug_show($str)
{
if($this->debug)
{
echo $str."<p>\r\n";
}
}
function send($from,$to,$subject,$body)
{
if($from == "" ¦ ¦ $to == "")
{
exit("請輸入信箱地址");
}
if($subject == "") $sebject = "無標題";
if($body == "") $body = "無內容";
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;

$All = "From:".$this->from."\n";
$All .= "To:".$this->to."\n";
$All .= "Subject:".$this->subject."\n";
$All .= $this->body;
/*
如過把$All的內容再加處理,就可以實現發送MIME郵件了
不過還需要加很多程序
*/

//以下是和伺服器會話
$this->in = "EHLO HELO\r\n";
$this->docommand();

$this->in = "AUTH LOGIN\r\n";
$this->docommand();

$this->in = $this->user."\r\n";
$this->docommand();

$this->in = $this->pass."\r\n";
$this->docommand();

$this->in = "MAIL FROM:".$this->from."\r\n";
$this->docommand();

$this->in = "RCPT TO:".$this->to."\r\n";
$this->docommand();

$this->in = "DATA\r\n";
$this->docommand();

$this->in = $All."\r\n.\r\n";
$this->docommand();

$this->in = "QUIT\r\n";
$this->docommand();

//結束,關閉連接

}
function docommand()
{
socket_write ($this->socket, $this->in, strlen ($this->in));
$this->debug_show("客戶機命令:".$this->in);
$this->result_str = "伺服器應答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);
}
}
//這個是我做的測試,我用的是smtp.163.com,那你的信箱也必須是163.com的,要不人家不讓你發!!
//你用這個類的時候你修改成你自己的信箱就可以了
$smtp = new smtp_mail("smtp.163.com","25","你的163.com的帳號","你的密碼");
//如果你需要顯示會話信息,請將上面的修改成
//$smtp = new smtp_mail("smtp.163.com","25","你的163.com的帳號","你的密碼",true);
$smtp->send("你的163.com的帳號@163.com","目標地址","你好","你好");

⑺ php email(); 關於這個函數的問題

需要配置php.ini文件,根據伺服器是Unix還是Windows的不同,配置方法不一樣,你打開php.ini文件就知道了,原本的模板如下:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
;sendmail_from = [email protected]

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

如果是WINDOWS伺服器就配置前面一段,如果是UNIX就配置最後的sendmail_path既可

⑻ 如何通過php發送郵件php的mail函數不能用!

支持mail的伺服器 一般都是linux的 國內的好像不多
自己的電腦安裝mail伺服器不能往外發的 呵呵 可以自己測試用
現在很多管理系統都是用fsocketopen方式連接郵件伺服器並發送郵件的 可以使用163 126的郵箱 網上有一些模型的 就像是好多管理系統後台讓填入用戶名和密碼 就能群發一樣 如果你不介意的話 給你轉發一個以前我自己改過的可以利用fsocketopen方式群發或者單發email的一共三個文件
MailClass.php 》》》》》》
<?php
class Smtp
{
var $host; //主機
var $port; //埠 一般為25
var $user; //SMTP認證的帳號
var $pass; //認證密碼
var $debug = false; //是否顯示和伺服器會話信息?
var $conn;
var $result_str; //結果
var $in; //客戶機發送的命令
var $from; //收件人收到郵件顯示的源信箱
var $email; //真實的地址
var $to; //目標信箱
var $subject; //主題
var $body; //內容
var $error;
var $All;
function Smtp($array)
{
$this->host = $array['host'];
$this->port = $array['port'];
$this->email= $array['trueemail'];
$this->from = $array['from'];
$this->user = base64_encode($array['username']);
$this->pass = base64_encode($array['password']);
$this->debug = $array['debug'];
$this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);

if($this->socket){
$this->result_str = "創建SOCKET:".socket_strerror(socket_last_error());
$this->debug_show($this->result_str);
}
else
die("初始化失敗,請檢查您的網路連接和參數");

$this->conn = socket_connect($this->socket,$this->host,$this->port);
if($this->conn){
$this->result_str = "創建SOCKET連接:".socket_strerror(socket_last_error());
$this->debug_show($this->result_str);
}
else
die("初始化失敗,請檢查您的網路連接和參數");

$this->result_str = "伺服器應答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);

}

function debug_show($str)
{
if($this->debug)
{
echo $str."<p>\r\n";
}
}

function setmail($to,$subject,$body){
$this->to = $to;
$this->subject = $subject;
$this->body = $body;

$All ="Content-type:text/html;charset=gb2312\r\n"; //郵件的編碼方式可以根據自己的需要改
$All .= "From:".$this->from."\r\n";
$All .= "To:".$this->to."\r\n";
$All .= "Subject:".$this->subject."\r\n\r\n";
$All .= $this->body;
$this->All = $All;
}
/**
* 發送郵件部分
* 接收郵箱數組
*/
function send($toarray,$subject,$body)
{
//以下是和伺服器會話
$this->in = "EHLO HELO\r\n";
$this->docommand();

$this->in = "AUTH LOGIN\r\n";
$this->docommand();

$this->in = $this->user."\r\n";
$this->docommand();

$this->in = $this->pass."\r\n";
$this->docommand();

foreach( $toarray as $to ) {
$this -> setmail($to,$subject,$body);

$this->in = "RSET\r\n";
$this->docommand();

$this->in = "MAIL FROM:<".$this->email.">\r\n";
$this->docommand();

$this->in = "RCPT TO:<".$this->to.">\r\n";
$this->docommand();

$this->in = "DATA\r\n";
$this->docommand();

$this->in = $this->All."\r\n.\r\n";
$this->docommand();
}

$this->in = "QUIT\r\n";
$this->docommand();

//結束,關閉連接
}
function docommand()
{
socket_write ($this->socket, $this->in, strlen ($this->in));
$this->debug_show("Client Action:".$this->in);
$this->result_str = "Server:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);
}
}
?>

MailConfig.inc.php 》》》》》》

<?php
$mailconfig['host'] = "smtp.126.com"; //主機
$mailconfig['port'] = "25"; //埠 一般為25
$mailconfig['trueemail'] = "[email protected]"; //真實的地址
$mailconfig['username'] = "mhz1600"; //SMTP認證的帳號
$mailconfig['password'] = "*****"; //改成自己的
$mailconfig['debug'] = false; //是否顯示和伺服器會話信息?
$mailconfig['from'] = "[email protected]"; //顯示給用戶的發件人

include_once "MailClass.php";
set_time_limit(180);
?>

SendDemo.php 》》》》》》
<?php
include_once "MailConfig.inc.php";

//簡單的臨時碼驗證 當前時間(到小時)的驗證碼
//if( empty($_GET['s']) || $_GET['s'] != md5(date('Y-m-d-H',time())) ) {header("http/1.1 404"); die('');}

//發送email
if( isset($_POST['sendmail']) ) {
if( isset($_POST['from']) ) $mailconfig['from'] = $_POST['from'];
$smtp = new Smtp($mailconfig);
$title = $_POST['title'];
//獲取post的email正文
if( get_magic_quotes_gpc() ) $message = $_POST['message'];
else $message = addslashes($_POST['message']);

//從email列表/文檔中分離出所有的email地址
$pregstr = "@[a-zA-Z0-9\_][0-9a-zA-Z\.\-\_]+\@[0-aA-Za-z\-\_]+\.[0-9a-zA-Z\.\-\_]+@is";
$temp = array();
preg_match_all($pregstr,$_POST['emails'],$temp);
$toarray = $temp[0];
//var_mp($toarray);

$smtp->send($toarray,$title,$message);

die("操作完成!<A href=".$_SERVER['PHP_SELF']."?s=".md5(date('Y-m-d-H',time())).">繼續發送其他</a> <a href=# onclick=window.close()>關閉</a>");
}
else {
if( isset($_POST['emails']) ) {
if( is_array($_POST['emails']) )
$emails = implode("\t",$_POST['emails']);
else
$emails = $_POST['emails'];
}
else $emails = "";
?>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
<table width="600" border="1" align="center" cellpadding="3" cellspacing="0" bordercolordark="#FFFFFF" bordercolorlight="#eeeeee">
<tr>
<td width="66">發件人:</td>
<td width="516"><input name="from" type="text" value="<?php echo $mailconfig['from']; ?>"> 可以直接修改mailconfig文件中的email</td>
</tr>
<tr>
<td>郵件標題:</td>
<td><input name="title" type="text" value="郵件群發測試標題!" size="60"></td>
</tr>
<tr>
<td>收件人:<br></td>
<td><textarea name="emails" cols="60" rows="5"><?php echo $emails; ?></textarea></td>
</tr>
<tr>
<td>郵件正文:<br>
【html】</td>
<td><textarea name="message" cols="60" rows="10">郵件群發測試!謝謝~!</textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="sendmail" value=" 發送郵件 "> </td>
</tr>
</table>
</form>
<?
}
?>
</body>
</html>

使用方式 運行senddemo.php就行 確定本地或者伺服器開啟了fsocketopen支持 在輸入框可以多種格式的的輸入很多email 程序用正則表達式匹配出所有的email地址 通過伺服器循環對話的方式不斷的發送郵件 看看那個demo的流程就明白了
【鄭重聲明:mailclass修改自網上的模型 其他本人原創,版權不究 歡迎分享】

+---------------------廣告-------------------------+
那一天:回憶,讓生活更美好
獨享人生中那個特別的日子,記錄從那一天開始的幸福
http://www.nayitian.net
期待您的加入,歡迎提供寶貴的意見建議
+--------------------------------------------------+

+--------------------補充--------------------+
發送郵件的伺服器(smtp)並不是網址 126發送郵件的伺服器是 smtp.126.com 網易163的發送郵件伺服器是 smtp.163.com 所有郵箱對於這個都有說明的 還有一個就是能夠使用這個功能的好象新注冊的郵箱不太好用 因為網易在2006年10對郵箱進行過調整 在此之前注冊的都沒問題 在這之後注冊的好像開通一些其他的功能並且使用了一段時間才行的
smtp伺服器的鏈接可以在命令提示行下測試 就是使用上面的命令:
首先 telnet smtp.126.com 25
因為smtp使用的25埠提供服務的 然後就會看到
220 126.com Anti-spam GT for Coremail System (126com[071018])
輸入 EHLO HELO
伺服器返回
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME

輸入 AUTH LOGIN
伺服器返回
334 dXNlcm5hbWU6
然後再輸入通過base64加密的用戶名和密碼 就能通過命令來和伺服器對話 包括發送郵件等功能

具體的如果有興趣更多命令自己查一下
這個php的程序就是模擬這個功能來實現的

如果你用telnet直接連不上的話 說明伺服器是錯誤的 。。

⑼ php如何接收發件箱郵件

php接收郵件舉例:
<?php
$server = "{bjmail.*.com/pop3}"; //郵件伺服器
$mailbox = "inbox"; //收件箱
$mailaccount="zhao**";//用戶名
$mailpasswd=" "; //密碼
$stream = @imap_open($server.$mailbox,$mailaccount,$mailpasswd);//打開IMAP 連結
$mail_number = imap_num_msg($stream);//信件的個數
if($mail_number < 1) { echo "No Message for $email"; }//如果信件數為0,顯示信息

for($i=$mail_number;$i>=$mail_number;$i--)
{
$headers = @imap_header($stream, $i);
$mail_header= imap_headerinfo($stream, $i);//郵件頭部
//var_mp ($mail_header);
$subject = $mail_header->subject;//郵件標題
$subject=decode_mime($subject);
echo $subject;

//編碼為簡體中文的標題的處理方法
// if(stristr($subject, "=?gb2312"))
// { //編碼為簡體中文的標題
// $subject=substr($subject,11);
// $subject=substr($subject,0,-2);
// $subject = base64_decode($subject);
// }
echo $from = $mail_header->fromaddress;//發件人
echo $date = $mail_header->date;//日期

$body = imap_fetchbody($stream, $i, 1);
$body = imap_base64($body);
$body = nl2br($body);
echo $body;

// $body = imap_qprint($body);
// echo $body;
// $body = imap_binary($body);
// $body = imap_base64($body);
//echo $body;

}
//對mime解碼
function decode_mime($string)
{
$pos = strpos($string,'=?');
if (!is_int($pos)) {
return $string;
}
$preceding = substr($string, 0, $pos); // save any preceding text
$search = substr($string, $pos+2); /* the mime header spec says this is the longest a single encoded Word can be */
$d1 = strpos($search, '?');
if (!is_int($d1)) {
return $string;
}
$charset = substr($string, $pos+2, $d1); //取出字元集的定義部分
$search = substr($search, $d1+1); //字元集定義以後的部分=>$search;
$d2 = strpos($search, '?');
if (!is_int($d2)) {
return $string;
}
$encoding = substr($search, 0, $d2); ////兩個?之間的部分編碼方式:q或b
$search = substr($search, $d2+1);
$end = strpos($search, '?='); //$d2+1 與 $end 之間是編碼了的內容:=> $endcoded_text;
if (!is_int($end)) {
return $string;
}
$encoded_text = substr($search, 0, $end);
$rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6)); //+6 是前面去掉的=????=六個字元
switch ($encoding) {
case 'Q':
case 'q':
//$encoded_text = str_replace('_', '%20', $encoded_text);
//$encoded_text = str_replace('=', '%', $encoded_text);
//$decoded = urldecode($encoded_text);
$decoded=quoted_printable_decode($encoded_text);
if (strtolower($charset) == 'windows-1251') {
$decoded = convert_cyr_string($decoded, 'w', 'k');
}
break;
case 'B':
case 'b':
$decoded = base64_decode($encoded_text);
if (strtolower($charset) == 'windows-1251') {
$decoded = convert_cyr_string($decoded, 'w', 'k');
}
break;
default:
$decoded = '=?' . $charset . '?' . $encoding . '?' . $encoded_text . '?=';
break;
}
return $preceding . $decoded .decode_mime($rest);
//return $preceding . $decoded . $this->decode_mime($rest);

}

熱點內容
java集合循環 發布:2024-04-27 01:17:18 瀏覽:593
解壓喪屍片 發布:2024-04-27 01:02:28 瀏覽:369
編程師加班 發布:2024-04-27 00:49:24 瀏覽:910
lol四川伺服器雲空間 發布:2024-04-27 00:42:08 瀏覽:934
卡宴怎麼看配置 發布:2024-04-27 00:41:08 瀏覽:941
央視影音緩存視頻怎麼下載視頻 發布:2024-04-27 00:25:55 瀏覽:583
手機緩存的視頻怎麼看 發布:2024-04-27 00:11:05 瀏覽:57
shell腳本平方計算公式 發布:2024-04-26 23:29:26 瀏覽:187
比較實惠的雲伺服器 發布:2024-04-26 23:24:57 瀏覽:974
怎麼增加電腦緩存 發布:2024-04-26 23:23:46 瀏覽:451