PHPMailer安装方法及简单实例

yipeiwu_com6年前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 = "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="发送"/>
</form>
</body>
</html>

相关文章

PHP通过iconv将字符串从GBK转换为UTF8字符集

1. iconv()介绍 iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件。例如:从GB2312转换为UTF-8。 iconv函数在php5中内置,GB字符集默认打开...

php和html的区别点详细总结

今天我来和大家讨论下关于PHP技术的另一个简单小问题,就是PHP代码和HTML代码的区别在哪里。 其实,如果简单的说,大家都知道,HTML是典型的静态网络编程用语,而PHP则是一种可实现...

php中访问修饰符的知识点总结

为什么需要访问权限? 防止覆盖变量名称和函数名称 我们下来看一下public的使用,public是可以从任何地方访问的最广泛的访问限定符。 假设A先生开发overlapFuncBase,...

PHP计数器的实现代码

复制代码 代码如下:<?php/*使用文本文件记录数据的简单实现*/$counter=1;if(file_exists("mycounter.txt")){$fp=fopen("m...

PHP测试成功的邮件发送案例

mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。 注意: 1、mail函数不支持esmtp协议,---即,只能直投,不能登陆 2、由上条,我们只能直投...