网页表单内容发送到指定邮箱

来源:互联网 发布:人工智能瓶颈 编辑:程序博客网 时间:2024/04/28 19:54

php 实现邮件自动发送之 PHPMailer
一、拥有自己的邮箱账号,
二、开启客户端授权码 (需要使用的密码就是,开启邮箱客户端授权后设置的密码。)

三、PHPMailer的下载
 邮件发送代码如下:
 

require 'PHPMailerAutoload.php';                       //加载需要使用的类, 或者使用:include("class.phpmailer.php");    include("class.smtp.php");$mail = new PHPMailer;//$mail->SMTPDebug = 3;                               // Enable verbose debug output$mail->isSMTP();                                      // Set mailer to use SMTP$mail->Host = 'smtp1.example.com';            // Specify main and backup SMTP servers  设置邮箱服务器,根据自己邮箱的类型而不同,比如163邮箱: $mail->Host = "smtp.163.com";$mail->SMTPAuth = true;                               // Enable SMTP authentication$mail->Username = 'user@example.com';                 // SMTP username          你自己的邮箱账号$mail->Password = 'secret';                           // SMTP password      你自己的账号密码$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted   邮箱服务器所使用的机密协议  163邮箱可以注释此项$mail->Port = 587;                                    // TCP port to connect to        163邮箱服务器端口为: 25$mail->setFrom('from@example.com', 'Mailer');$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient    可以设置发给多个用户$mail->addAddress('ellen@example.com');               // Name is optional  $mail->addReplyTo('info@example.com', 'Information');$mail->addCC('cc@example.com');$mail->addBCC('bcc@example.com');$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments    添加附件,没有附件的话,注释即可$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name$mail->isHTML(true);                                  // Set email format to HTML$mail->Subject = 'Here is the subject';          //邮件的主题$mail->Body    = 'This is the HTML message body <b>in bold!</b>';            //邮件的内容$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';if(!$mail->send()) {    echo 'Message could not be sent.';    echo 'Mailer Error: ' . $mail->ErrorInfo;} else {

PHPMailer 的简单使用

require_once('class.phpmailer.php');require_once("class.smtp.php"); $mail  = new PHPMailer(); $mail->CharSet    ="UTF-8";                 //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置为 UTF-8$mail->IsSMTP();                            // 设定使用SMTP服务$mail->SMTPAuth   = true;                   // 启用 SMTP 验证功能$mail->SMTPSecure = "ssl";                  // SMTP 安全协议$mail->Host       = "smtp.gmail.com";       // SMTP 服务器$mail->Port       = 465;                    // SMTP服务器的端口号$mail->Username   = "your_name@gmail.com";  // SMTP服务器用户名$mail->Password   = "your_password";        // SMTP服务器密码$mail->SetFrom('发件人地址', '发件人名称');    // 设置发件人地址和名称$mail->AddReplyTo("邮件回复人地址","邮件回复人名称");                                             // 设置邮件回复人地址和名称$mail->Subject    = '';                     // 设置邮件标题$mail->AltBody    = "为了查看该邮件,请切换到支持 HTML 的邮件客户端";                                             // 可选项,向下兼容考虑$mail->MsgHTML('');                         // 设置邮件内容$mail->AddAddress('收件人地址', "收件人名称");//$mail->AddAttachment("images/phpmailer.gif"); // 附件 if(!$mail->Send()) {    echo "发送失败:" . $mail->ErrorInfo;} else {    echo "恭喜,邮件发送成功!";}
0 0