PHPMailer安裝方法及簡單實(shí)例
更新時(shí)間:2008年11月25日 18:56:45 作者:
PHPMailer是一個(gè)用PHP寫的用于郵件發(fā)送的類,有點(diǎn)像Jmail,相信很多新手和我一樣,開始很茫然,不知道怎么安裝,查找了一下,發(fā)現(xiàn)這方面的資料真的少之又少,一個(gè)文章被轉(zhuǎn)載千百次,一搜索全是同一個(gè)內(nèi)容,真不知道說什么好,其實(shí)打開安裝里的readme就一目了然了,閑話少說,安裝其實(shí)很簡單。
打開你電腦里的PHP.INI文件,找到如下位置,添加紅線部分的內(nèi)容,路徑就是你PHPMailer存放的位置:

保存,重啟apache.
然后借用readme里的一個(gè)例子,稍微改一下就可以用了,由于只做最簡單的測試,很多東西我注釋掉了。
send.php
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$address = $_POST['address'];
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.songzi.org"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "phpmailer@songzi.org"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = "phpmailer@songzi.org";
$mail->FromName = "songzi";
$mail->AddAddress("$address", "");
//$mail->AddAddress(""); // name is optional
//$mail->AddReplyTo("", "");
//$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
//$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "PHPMailer測試郵件";
$mail->Body = "Hello,這是松子的測試郵件";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
test.php
<html>
<body>
<h3>phpmailer Unit Test</h3>
請你輸入<font color="#FF6666">收信</font>的郵箱地址:
<form name="phpmailer" action="send.php" method="post">
<input type="hidden" name="submitted" value="1"/>
郵箱地址: <input type="text" size="50" name="address" />
<br/>
<input type="submit" value="發(fā)送"/>
</form>
</body>
</html>

保存,重啟apache.
然后借用readme里的一個(gè)例子,稍微改一下就可以用了,由于只做最簡單的測試,很多東西我注釋掉了。
send.php
復(fù)制代碼 代碼如下:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$address = $_POST['address'];
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.songzi.org"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "phpmailer@songzi.org"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = "phpmailer@songzi.org";
$mail->FromName = "songzi";
$mail->AddAddress("$address", "");
//$mail->AddAddress(""); // name is optional
//$mail->AddReplyTo("", "");
//$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
//$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "PHPMailer測試郵件";
$mail->Body = "Hello,這是松子的測試郵件";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
test.php
復(fù)制代碼 代碼如下:
<html>
<body>
<h3>phpmailer Unit Test</h3>
請你輸入<font color="#FF6666">收信</font>的郵箱地址:
<form name="phpmailer" action="send.php" method="post">
<input type="hidden" name="submitted" value="1"/>
郵箱地址: <input type="text" size="50" name="address" />
<br/>
<input type="submit" value="發(fā)送"/>
</form>
</body>
</html>
您可能感興趣的文章:
相關(guān)文章
php實(shí)現(xiàn)的XML操作(讀取)封裝類完整實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)的XML操作(讀取)封裝類,給出了xml格式文件示例,并結(jié)合完整實(shí)例形式分析了php遍歷讀取xml格式數(shù)據(jù)節(jié)點(diǎn)的相關(guān)操作技巧,需要的朋友可以參考下2017-02-02php 5.6版本中編寫一個(gè)PHP擴(kuò)展的簡單示例
這篇文章主要介紹了php 5.6版本中編寫一個(gè)PHP擴(kuò)展的簡單示例,本文給出擴(kuò)展實(shí)現(xiàn)代碼、編譯方法、配置方法和使用例子等內(nèi)容,需要的朋友可以參考下2015-01-01用php+javascript實(shí)現(xiàn)二級級聯(lián)菜單的制作
二級級聯(lián)菜單在我去年的時(shí)候就用asp+js做過,而現(xiàn)在忽然拿出來再做的時(shí)候我發(fā)現(xiàn)我忘記了,而且原來用asp寫的程序都找不到了,真暈[emot]sweat[/emot],于是到網(wǎng)上搜,找了半天,我發(fā)現(xiàn)網(wǎng)上的寫法各異,而且都特別復(fù)雜,這么一個(gè)二級級聯(lián)菜單,有必要弄這么復(fù)雜嗎?于是自己想重新寫一個(gè)簡單的。在經(jīng)過半個(gè)小時(shí)左右的思考后,我完成了二級級聯(lián)菜單的設(shè)計(jì)和制作。2008-05-05php刪除頁面記錄 同時(shí)刷新頁面 刪除條件用GET方式獲得
在某個(gè)頁面上顯示查詢數(shù)據(jù),并在每條數(shù)據(jù)后增加刪除功能,點(diǎn)擊“刪除”,刪除掉數(shù)據(jù),同時(shí)刷新頁面2012-01-01php流量統(tǒng)計(jì)功能的實(shí)現(xiàn)代碼
用php實(shí)現(xiàn)的流量統(tǒng)計(jì)功能代碼,本代碼僅供學(xué)習(xí)交流,其中必有不妥之處。請見諒2012-09-09