PHPMailer安装方法及简单实例

yipeiwu_com5年前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设计模式 Factory(工厂模式)

复制代码 代码如下: <?php /** * 工厂方法模式 * * 定义一个用于创建对象的接口,让子类决定将哪一个类实例化,使用一个类的实例化延迟到其子类 */ /* class...

php下关于Cannot use a scalar value as an array的解决办法

今天在测试php程序的时候,出现了一个错误提示:Cannot use a scalar value as an array,这个错误提示前几天也出过,当时好像稍微调了一下就好了,也没深究...

在普通HTTP上安全地传输密码

1。理论      在普通HTTP上,一般表单中的密码都是以明文方式传到服务器进行处理的。这无疑给了坏人以可乘之机!这里我们就说说怎么传...

PHP警告Cannot use a scalar value as an array的解决方法

看到php的错误日志里有些这样的提示: [27-Aug-2011 22:26:12] PHP Warning: Cannot use a scalar value as an array...

php5与php7的区别点总结

php5与php7的区别是什么?下面本篇文章就来给大家对比一下php5与php7,介绍php5与php7之间的区别。有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。 php...