利用php中的phpmailer发送邮件的示例,示例代码以及该示例的页面效果如下,另外文章的末尾提供了phpmailer文件的下载地址,该文件里面有许多发送邮件的例子,不过都是英文的。
具体代码:
<html xmlns="http://www.feishuai.vip/php-function/378.html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>利用phpmailer发送电子邮件</title>
<?php
if(isset($_POST['email'])&&trim($_POST['email'])!=''){
require "class.phpmailer.php";
$mail=new PHPMailer();
$address=$_POST['email'];
$mail->IsSMTP();//使用SMTP方式发送
$mail->Host="mail.xxxxx.com";//您的企业邮局域名
$mail->SMTPAuth=true;//启用SMTP验证功能
$mail->Username="user@xxxx.com";//邮局用户名(请填写完整的email地址)
$mail->Password="******";//邮局密码
$mail->From="user@xxxx.com";//邮件发送者email地址
$mail->FromName="您的名称";
$mail->AddAddress($address,"");//AddAddress("收件人email","收件人姓名")
//$mail->AddReplyTo("","");//http://www.feishuai.vip/php-function/378.html
//$mail->AddAttachment("/var/tmp/file.tar.gz");//添加附件
//$mail->IsHTML(true);//set email format to HTML //是否使用HTML格式
$mail->Subject=$_POST['title'];//邮件标题
$mail->Body=$_POST['content'];//邮件内容
$mail->AltBody='';//附加信息,可以省略
if(!$mail->Send()){
echo "邮件发送失败。 <p>";
echo "错误原因:".$mail->ErrorInfo;
}else{
echo "邮件发送成功";
}
}
?>
</head>
<body>
<h3>phpmailer Email 发送</h3>
<form name="phpmailer" action="index.php" method="post">
<input type="hidden" name="submitted" value="1"/>
邮件地址: <input type="text" size="50" name="email" />
<br/>
邮件标题: <input type="text" size="50" name="title" />
<br/>
邮件信息:
<textarea name="content" id="content" cols="45" rows="5"></textarea>
<br />
<input type="submit" value="发送"/>
</form>
</body>
</html>