利用phpmailer 发送邮件代码[发送html内容]
<?php
@session_start();
include(dirname(__FILE__).'./inc/function.php');
require(dirname(__FILE__)."/mail/class.phpmailer.php");
$array = array_unique(Get_value('mail',1));
$type = Get_value('type',1);
$mail = new PHPMailer();
$count =0;
$bad =0;
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.163.com"; // smtp1.example.com;smtp2.example.comspecify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mailangel123"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = "mailangel123@163.com";
$mail->FromName = "你的好友来信";
$MailBody = GetContent($type);
//$array =explode('|',$rs['mail']);
foreach( $array as $tmpmail ){
if( @preg_match("/w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*/",$tmpmail)
|| strlen($User_Mail)<6 )
{
$mail->AddReplyTo("mailangel123@163.com", "44");
$mail->AddAddress($tmpmail,'您好!');
$mail->WordWrap = 50;
$mail->CharSet="GB2312";
//$mail->AddAttachment("/var/tmp/file.tar.gz");
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true);
$mail->Subject = "你的朋友邀请你一起合影!";
$mail->Body = $MailBody;
if(!$mail->Send())
{
$bad++;
$mail->ClearAddresses();
$mail->ClearAttachments();
}
else
{
$count++;
}
}
ShowMsg("result:$count");
}
下面这个文章是读取html 文档并进行html发送哦,
function GetContent($type){
if( $type )
{
if(file_exists('./mail_room.html') )
{
$content = file_get_contents( './mail_room.html');
}
else
{
ShowMsg('file can' read fail ');
}
}
else
{
if( file_exists( './mail_person.html') )
{
$content = file_get_contents( './mail_person.html');
}
else
{
ShowMsg('person file read fail!');
}
}
return $content;
}
/* echo "<script>alert('发关".$count."邮件成功');</script>"; */
?>
本站原创http://www.111cn.net 转载请注明
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>--邀请好友参加</title>
<style type="text/css">
<!--
body {
margin: 0px;
padding: 0px;
font-size: 12px;
background-color: #CFCFCF;
}
input {
line-height: 18px;
height: 18px;
border: 1px solid #CCCCCC;
}
img {
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
}
* {
margin: 0px;
padding: 0px;
list-style-image: none;
list-style-type: none;
background-repeat: no-repeat;
}
td {
line-height: 22px;
font-size: 14px;
font-weight: 700;
color: #276662;
}
-->
</style>
</head>
<body>
<form action="#" method="post" name="form">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="572" height="227" valign="top" background="img/mailfooterimg.gif"><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="70"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="text" value="http://111cn.net/" size="60" /></td>
<td height="40"><a href="#"><img src="img/copy.gif" width="72" height="22" /></a></td>
</tr>
</table></td>
</tr>
<tr>
<td height="28">好友姓名:
<input type="text" size="22" />
邮箱地址:
<input type="text" size="22" /> </td>
</tr>
<tr>
<td height="28">好友姓名:
<input type="text" size="22" />
邮箱地址:
<input type="text" size="22" /> </td>
</tr>
<tr>
<td height="28">好友姓名:
<input type="text" size="22" />
邮箱地址:
<input type="text" size="22" /> </td>
</tr>
<tr>
<td height="28" align="right"><a href="#"><img src="img/sendbtn.gif" width="95" height="26" /></a></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
发送邮件处理功能页面。
mail.php
<?
require(dirname(__FILE__)."/mail/class.phpmailer.php"); //调用 phpmailer类型,如果没有phpmailer请点击这里下载phpmailer for php5/6 下载
$array = array_unique(Get_value('mail',1));//去除重复的邮箱地址
$mail = new PHPMailer();
$count =0;
$bad =0;
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.163.com"; // smtp1.example.com;smtp2.example.comspecify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mailangel123"; // SMTP username
$mail->Password = "*******"; // SMTP password
$mail->From = "mailangel123@163.com";
$mail->FromName = "你的好友来信";
$MailBody = '内容'
$mail->AddReplyTo("mailangel123@163.com", "澳优");
$mail->AddAddress($tmpmail,'您好!');
$mail->WordWrap = 50;
$mail->CharSet="GB2312";
//$mail->AddAttachment("/var/tmp/file.tar.gz");
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true);
$mail->Subject = "你的朋友邀请你一起合影!";
$mail->Body = $MailBody;
if(!$mail->Send())
{
$bad++;
$mail->ClearAddresses();
$mail->ClearAttachments();
}
OK就完成了哦。
?>
php自带了邮件发送函数,我们可以使用mail来进行发送邮件,下面我们就来看一个使用mail进行发邮件的实例教程吧。代码如下 | 复制代码 |
<?php |
<?php
//定义边界线
$boundary = uniqid( "" );
//生成邮件头
$header = "From: $from Content-type: multipart/mixed;
boundary="$boundary" X-Mailer:PHP X-Priority:3";
//获取附件文件的MIME类型
$mimetype = mime_content_type('test.zip')
//获取附件文件的名字
$attach = 'test.zip'
//对附件文件进行编码和切分
$fp = fopen($attach, "r");
$content = fread($fp, filesize($attach));
$content = chunk_split( base64_encode($content) );
//生成邮件主体
$body ="
--$boundary
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit
$message
--$boundary
Content-Type: $mimeType; name=$filename
Content-Disposition: attachment; filename=$filename
Content-Transfer-Encoding: base64
$content
--$boundary--";
//发送邮件
mail( $to, $subject, $body, $header );
?>
转载请注明:www.111cn.net
mail ( )函数可让您发送电子邮件直接从脚本,讲法mail(to,subject,message,headers,parameters)定义和用法
在mail ( )函数可让您发送电子邮件直接从脚本。
此函数返回TRUE电子邮件是否已成功接受交付,否则返回FALSE 。
语法
mail(to,subject,message,headers,parameters)
to | 收信人 |
subject | 标题 |
message | 内容 |
headers | 任择。指定额外的标题一样,从,副本,并密件副本。额外的标题应该是分开的CRLF ( r n )段。注意:当发送电子邮件,它必须包含一个从头。这可以设置此参数或在php.ini文件。 |
parameters | 任择。指定一个额外的参数邮件程序(一个界定的sendmail_path配置设置) 。 (即本可用来设置信封发件人地址邮件时使用的口邮件选项) |
提示和说明
注意:请记住,仅仅因为电子邮件被接受交付,但这并不意味着电子邮件实际上是发送和接收。
范例1
发送一个简单的电子邮件:
$txt = "First line of textnSecond line of text";// Use wordwrap() if lines are longer than 70 characters $txt = wordwrap($txt,70);// Send email mail("somebody@example.com","My subject",$txt);
相关文章
- 本文给大家介绍的是nodejs实现使用阿里大鱼短信API发送消息的方法和代码,有需要的小伙伴可以参考下。...2016-01-20
- mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
- 这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<?php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
- 这篇文章主要介绍了c# 如何实现发送邮件的功能,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-07
- 这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<?php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
- 这篇文章主要介绍了python实现企业微信定时发送文本消息的实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-25
- 这篇文章主要介绍了c#使用netmail方式发送邮件的示例,大家参考使用吧...2020-06-25
- mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
- PHPMailer在SAE上无法发送邮件怎么回事呢,我们以前在php5.2.7版本中使用了PHPMailer是可以发,但移到sae中发现无法发邮件了,那么此问题如何解决 在SAE上直接用5.2.7...2016-11-25
- 本文我们整理了三个android后台发送邮件的方法及示例,第一个是不借助Intent在android后台发送Email,第二个是用在收集应用的异常信息,第三个是分享一个android后台发送邮...2016-09-20
- 这篇文章主要介绍了Perl中使用MIME::Lite发送邮件实例,本文介绍了使用sendmail方式发送、发送HTML格式邮件、smtp方式发送邮件等内容,需要的朋友可以参考下...2020-06-29
网上找到的两个PHP发送邮件的例子,很不错,贴出来给初学者参考吧(不知道是否有兄弟曾贴过),呵呵(2
Advanced Example Here we will show the full capabilities of the PHP mail function. PHP Code: <?php echo "<html><body>"; $recipient = "Kris Arndt <karn@nu...2016-11-25- 学过asp的朋友可能知道jmail组件是使用在asp中一个常用的邮箱发送功能,在php中如果想调用jmail功能我们需要使用com组件来操作。 我们先来介绍格式 代码如...2016-11-25
- //原创:www.111cn.net 注明:转载说明来处www.111cn.net // 昨天听一网友说用php 里面的mail发邮件发不出去,我想一般都是发不了的,现在大多数据邮件提供商都不准那样了...2016-11-25
- 这篇文章主要介绍了C#编程实现发送邮件的方法,具备添加附件的功能,涉及C#文件传输及邮件发送的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 本文章来介绍人一下关于与我们不同的发送邮件的方法我们来利用php curl stmp来实现邮件的发送程序。 $ telnet 邮箱SMTP服务地址 25 Trying 邮箱服务IP地址......2016-11-25
- 这篇文章主要介绍了Python基于httpx模块实现发送请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-08
node.js 基于 STMP 协议和 EWS 协议发送邮件
这篇文章主要介绍了node.js 基于 STMP 协议和 EWS 协议发送邮件的示例,帮助大家更好的理解和使用node.js,感兴趣的朋友可以了解下...2021-02-15- <?php // 请求 PHPmailer类 文件 require_once("class.phpmailer.php"); //发送Email函数 function smtp_mail ( $sendto_email, $subject, $body, $extra_hd...2016-11-25
解决PHPMailer错误SMTP Error: Could not connect to SMTP host的办法
PHPMailer发邮件时提示SMTP Error: Could not connect to SMTP host错误是smtp服务器的问题我们一起来看看关于SMTP Error: Could not connect to SMTP host问题的解...2016-11-25