導航:首頁 > 編程語言 > php郵件

php郵件

發布時間:2022-01-18 09:40:15

php郵件發送

可以的,PHP直接連接SMTP伺服器,進行登錄和發送郵件。不過不可能簡單哦,相當於編寫一個OUTLOOK的功能,不可能很簡單,可以參見這篇文章:http://www.chinaz.com/Program/PHP/041050242007.html

② 使用php 怎麼發送郵件

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

③ PHP 郵件收發判斷

if (!(mail ($mail_to, $mail_subject, $mail_body, $headers))) {
你這句已經執行了一次mail

當成功後,下面你又調用了一次mail,所以兩次

④ 用PHP怎樣實現郵件的自動回復

立即回復用mail函數;
mail(string to, string subject, string message, string [additional_headers]);

⑤ 如何使PHP郵件()工作

PHP 簡易 E-Mail
通過 PHP 發送電子郵件的最簡單的方式是發送一封文本 email。
在下面的例子中,我們首先聲明變數($to, $subject, $message, $from, $headers),然後我們在 mail() 函數中使用這些變數來發送了一封 e-mail:
<?php

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

?>

PHP Mail Form
通過 PHP,您能夠在自己的站點製作一個反饋表單。下面的例子向指定的 e-mail 地址發送了一條文本消息:
<html>
<body>

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "[email protected]", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>

</body>
</html>

例子解釋:
首先,檢查是否填寫了郵件輸入框
如果未填寫(比如在頁面被首次訪問時),輸出 HTML 表單
如果已填寫(在表單被填寫後),從表單發送郵件
當點擊提交按鈕後,重新載入頁面,顯示郵件發送成功的消息

⑥ 跪求懂php郵件接收的大神給指點一下怎樣實現郵件的接收功能

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

<?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();
}
}
?>

望採納 Thx

⑦ php怎麼寫郵件發送

Outlook Express 設置
(提示:如果8、9、10沒有設定,會發不出郵件,只能接收)
以中文版 Outlook Express 6 為例,請按以下步驟,手動配置你的客戶端:
1、打開 Outlook Express 後,單擊窗口中的「工具」菜單,選擇「帳戶」;
2、點擊「郵件」標簽,點擊右側的「添加」按鈕,在彈出的菜單中選擇「郵件」;
3、彈出的對話框中,根據提示,輸入你的「顯示名」, 然後點擊「下一步」;
4、輸入你的電子郵件地址,點擊「下一步」
5、輸入你郵箱的的 POP 和 SMTP 伺服器地址:(一般在你的郵箱頁面或幫助中有,以下以126郵箱為例說明)
pop: pop.126.com
smtp: smtp.126.com
再點擊「下一步」;
6、輸入你的帳號及密碼(此帳號為登錄此郵箱時用的帳號,僅輸入 @ 前面的部分),再點擊「下一步」;
7、單擊「完成」按鈕保存你的設置;
8、設置 SMTP 伺服器身份驗證:在「郵件」標簽中,雙擊剛才添加的帳號,彈出此帳號的屬性框;
9、請點擊「伺服器」標簽,然後在「發送郵件伺服器」處,選中「我的伺服器要求身份驗證」選項,並點擊右邊「設置」標簽,選中「使用與接收郵件伺服器相同的設置」。
10、點擊「確定」,然後「關閉」帳戶框。
現在你已設置成功,點擊主窗口中的「發送接收」按鈕即可進行郵件收發。
(提示:如果8、9、10沒有設定,會發不出郵件,只能接收)

⑧ 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);

}

⑨ PHP發郵件的問題

如果樓主是自己寫的SMTP類那麼建議你仔細檢查一下SOCKET會話過程
說不定它的SMTP伺服器的驗證過程跟你提供的信息不一致導致的會話錯誤

可以適當修改一下登錄驗證過程的代碼試試

⑩ 怎麼利用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郵件相關的資料

熱點內容
解壓電波歌曲大全 瀏覽:336
為啥文件夾移到桌面成word了 瀏覽:858
命令符的安全模式是哪個鍵 瀏覽:758
編程中學 瀏覽:956
單片機求助 瀏覽:992
ug加工側面排銑毛坯怎麼編程 瀏覽:271
程序員有關的介紹 瀏覽:736
支付寶使用的什麼伺服器 瀏覽:210
安卓看本地書用什麼軟體好 瀏覽:921
經傳軟體滾動凈利潤指標源碼 瀏覽:522
螢石雲視頻已加密怎麼解除 瀏覽:574
一命令四要求五建議 瀏覽:30
qq文件夾遷移不了 瀏覽:19
液體粘滯系數測定不確定度演算法 瀏覽:332
輕棧源碼 瀏覽:426
把圖片壓縮到500k 瀏覽:35
命令你自己 瀏覽:369
51單片機c語言pdf下載 瀏覽:177
androidactivity堆棧 瀏覽:821
mac執行命令 瀏覽:897