程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHPMailer安裝方法及簡單實例

PHPMailer安裝方法及簡單實例

編輯:關於PHP編程

打開你電腦裡的PHP.INI文件,找到如下位置,添加紅線部分的內容,路徑就是你PHPMailer存放的位置:
attachments/200611/29_150901_phpmailer.jpg
保存,重啟apache.
然後借用readme裡的一個例子,稍微改一下就可以用了,由於只做最簡單的測試,很多東西我注釋掉了。
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 = "[email protected]"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = "[email protected]";
$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="發送"/>
</form>
</body>
</html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved