php邮件图片,PHPMailer 发送邮件内容带图片的邮件

首先mail.class.php :

include_once('class.phpmailer.php');

class mail{

private

$mail;

private

$body = '/p>

"-//W3C//DTD HTML 4.01

Transitional//EN">

Whty Email

Center

http-equiv="Content-Type"

content="text/html;

charset=UTF-8">

';

public

function Instance($user = 'lxx@xx',$pwd = 'xx',$host = 'xx')

{

$this->mail = new PHPMailer(true);

$this->mail->CharSet =

'utf-8';

// 设置编码

$this->mail->IsSMTP();

// tell the class to use SMTP

//$mail->IsMail();

// tell the class to use MAIL

$this->mail->SMTPAuth

=

false;

// enable SMTP authentication

//$this->mail->Port

=

25;

// set the SMTP server port

$this->mail->Host

=

$host;

// SMTP server

$this->mail->Username

=

$user;

// SMTP server username

$this->mail->Password

=

$pwd;

// SMTP server password

//$this->MFrom();

//$this->MFromName();

}

public

function  mFrom($from = 'rttrtr@saa')

{

$this->mail->From = $from;

}

public

function mFromName($name = 'linweijie')

{

$this->mail->FromName = $name;

}

public

function mTo($to,$name)

{

if($to)

$this->mail->AddAddress($to,$name);

else die('mail error : 收件人不能为空');

}

public

function mSubject($subject)

{

$this->mail->Subject =

$subject;

}

public

function mAttachment($attachment,$attachmentName = '')

{

if(file_exists(iconv("UTF-8",

"GB2312", $attachment))){

if(!$attachmentName){

$arr = explode('/',$attachment);

$attachmentName = $arr[count($arr) - 1];

}

$this->mail->AddAttachment(iconv("UTF-8",

"GB2312",

$attachment),$attachmentName);

}

else die('mail error : 附件不存在');

}

public

function mBody($body)

{

if($body) {

$this->body =

str_replace('',$body,$this->body);

$this->body = preg_replace('/\\\\/','',

$this->body); //Strip backslashes

}

else die('mail error : 邮件内容不能为空');

}

public

function mSend()

{

try{

$this->mail->MsgHTML($this->body);

$this->mail->IsHTML(true);

$this->mail->Send();

return true;

}

catch (phpmailerException $e){

die($e->errorMessage());

}

}

}

?>

调用邮件发送类:

include_once('mail.class.php');

$mail = new mail();

$mail->Instance();

$mail->mFrom(‘xx’);

$mail->mFromName('xxx');

$mail->mTo('xxx@xx','lin');

$mail->mBody('

$name,

你好:

align="center">xxx

align="center">

src="test.png"

alt="测试图片"

/>

');

//test.png 在当前目录

$mail->mSubject('邮件测试--主题');

$mail->mAttachment('README');//附件

$back = $mail->mSend();

echo

"";

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值