php记录邮件发送,有关php邮件发送一点记录

php邮件发送需要准备2个文件:一个是 class.phpmailer.php',另一个是:class.smtp.php

//文件导入,及参数获取省去。。。。

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {

$mail->Host = "smtp.gmail.com"; // SMTP server

$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)

$mail->SMTPAuth = true; // enable SMTP authentication

$mail->SMTPSecure = "ssl"; // sets the prefix to the servier

$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server

$mail->Port = 465; // set the SMTP port for the GMAIL server

$mail->Username ='sgo@gmail.com'; // GMAIL username

$mail->Password = "123456"; // GMAIL password

$mail->AddReplyTo('sgo@gmail.com', 'test');

$mail->AddAddress($email, $username);//根据传进来的邮件地址参数,发送邮件

$mail->SetFrom('sgo@gmail.com', 'test');

$mail->AddReplyTo('sgo@gmail.com', 'test');

//以上邮箱的配置,qq和gmail都测试过,不过新的qq邮箱会把邮件截住,老的qq邮箱还是挺顺畅的。

$mail->Subject = 'Welcome!';

$mail->AltBody = 'Go!'; // optional - MsgHTML will create an alternate automatically

$body ="you_logo.png%5C%22";

// 邮件的发送大概有2种方式:

一种是直接发送静态页面 $mail->MsgHTML(file_get_contents('contents.html'));//$mail->MsgHTML(file_get_contents('views/find.html'));这一种方式发送比较简洁,不过很难向静态页面传递参数

另一种是构建body,这一种比较费时,但是容易传参,一下就构建body的常用格式的一点记录

$mail->Body="

%5C%22cid:my-attach%5C%22//在邮件里构建图片

"

系统自动发送了该邮件

"//一般的文字

"

请点击://a标签的写法,双引号要转义

body结束,下面是附件

$mail->AddEmbeddedImage('views/image/you_logo.png',"my-attach"); // 向刚才构建的图片里嵌入一张图片,my-attach是cid

//$mail->AddAttachment('images/phpmailer_mini.gif'); //加入附件,附件形式可以是图片、声音等等

//$mail->Send();邮件发送

//echo $mail->Send();

if($mail->Send()){

$this->redirect('/simple/send?email='.$email);

}else{

echo "mail test!!!";

}

} catch (phpmailerException $e) {

echo $e->errorMessage(); //Pretty error messages from PHPMailer

} catch (Exception $e) {

echo $e->getMessage(); //Boring error messages from anything else!

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值