php?
ini_set("magic_quotes_runtime",0);?
require?'class.phpmailer.php';?
try?{?
$mail?=?new?PHPMailer(true);?
$mail-IsSMTP();?
$mail-SMTPAuth?=?true;?//开启认证?
$mail-Password?=?"这是密码";?
//$mail-IsSendmail();?//如果没有sendmail组件就注释掉,否则出现"Could?not?execute:?/var/qmail/bin/sendmail?"的错误提示?
$mail-FromName?=?"";?
$mail-AddAddress($to);?
$mail-Subject?=?"phpmailer测试标题";?
$mail-Body?=?"h1phpmail演示/h1这是php点点通(font?color=red;/font)对phpmailer的测试内容";?
$mail-AltBody?=?"To?view?the?message,?please?use?an?HTML?compatible?email?viewer!";?//当邮件不支持html时备用显示,可以省略?
//$mail-AddAttachment("f:/test.png");?//可以添加附件?
$mail-IsHTML(true);?
$mail-Send();?
echo?'邮件已发送';?
}?catch?(phpmailerException?$e)?{?
echo?"邮件发送失败:".$e-errorMessage();?
}?
PHP虽然提供了mail()函数,但并不好用,而PHPMailer是一个不错的邮件发送工具,此时此刻呢将详细介绍,需要了解的朋友可以参考下:
[php] view plain copy
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$headers = "From: $from";
$send=mail($to,$subject,$message,$headers);
if($send)
echo "Mail Sent";
else
echo "Sorry,mail sent failed!"
/span
在CSDN论坛上发现phpmailer可以方便快捷的发送邮件,以下写出详细使用教程:
以下为前台表单php代码:
body
form name="phpmailer" action="testemail.php" method="post"
input type="hidden" name="submitted" value="1"/
br/
input type="submit" value="发送"/
/form
/body
/html /span
以下为后台程序:
php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/
ini_set("magic_quotes_runtime",0);
require('class.phpmailer.php');
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
//$body = file_get_contents('contents.html');
//$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$to = $_POST['to'];
$mail-IsSMTP(); // tell the class to use SMTP
$mail-SMTPAuth = true; // enable SMTP authentication
$mail-Host = "smtp.qq.com"; // SMTP server
$mail-Password = "000000000000"; // SMTP server password
//$mail-IsSendmail(); // tell the class to use Sendmail
$mail-FromName = "han qing";
$mail-AddAddress($to);
$mail-Body = "h1phpmailer演示/h1 这是用PHPMAILER发的第一份邮件,从QQ邮箱发到Google邮箱.";
$mail-AddAttachment("F:/myloe.jpg");
$mail-AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
//$mail-MsgHTML($body);
$mail-IsHTML(true); // send as HTML
$mail-Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e-errorMessage();
}
require_once('class.phpmailer.php');
require_once("class.smtp.php");?
$mail?=?new?PHPMailer();?
$mail-IsSMTP();?????//?设定使用SMTP服务
$mail-SMTPAuth?=?true;????//?启用?SMTP?验证功能
$mail-SMTPSecure?=?"ssl";???//?SMTP?安全协议
$mail-Host??=?"smtp.gmail.com";??//?SMTP?服务器
$mail-Username?=?"your_name@gmail.com";?//?SMTP服务器用户名
$mail-Password?=?"your_password";??//?SMTP服务器密码
$mail-SetFrom('发件人地址',?'发件人名称');?//?设置发件人地址和名称
$mail-AddReplyTo("邮件回复人地址","邮件回复人名称");?
??//?设置邮件回复人地址和名称
$mail-Subject?=?'';????//?设置邮件标题
??//?可选项,向下兼容考虑
$mail-MsgHTML('');?????//?设置邮件内容
$mail-AddAddress('收件人地址',?"收件人名称");
//$mail-AddAttachment("images/phpmailer.gif");?//?附件?
if(!$mail-Send())?{
echo?"发送失败:"?.?$mail-ErrorInfo;
}?else?{
echo?"恭喜,邮件发送成功!";
以上就是土嘎嘎小编为大家整理的php网站发送邮件相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!