当前位置:首页 > PHP教程 > PHP高级教程

PHPMailer安装方法及简单实例

打开你电脑里的php.ini文件,找到如下位置,添加红线部分的内容,路径就是你phpmailer存放的位置:

保存,重启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>


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!