zoukankan      html  css  js  c++  java
  • php 使用phpmailer 发送邮件(附带中文乱码的解决方法)

    下载phpmailer ,在程序里包含class.phpmailer.php 类  ,这里有中文乱码的解决方法

    实例代码如下

    <html>
        <head>
            <title>PHPMailer - Mail() basic test</title>
        </head>
        <body>
    
            <?php
            //header( "Content-type: text/html; charset=UTF-8" );    //设置本地编码
            //setlocale( LC_ALL, 'GBK' );
            //error_reporting(E_ALL);
            error_reporting( E_STRICT );
    
            date_default_timezone_set( 'America/Toronto' );
    
            require_once('class.phpmailer.php');    //必须包含的文件
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
    
            $mail = new PHPMailer();
            $mail->CharSet = "UTF-8";        //中文环境下需要设置编码
            //  $body = file_get_contents( 'contents.html' );    //包含网页的使用方法
            //$body = eregi_replace( "[]", '', $body );
            $body = '测试邮件,附上中文乱码解决方法:' . "<br>" .'123';   //设置邮件内容   使用 <br> 换行
            $mail->IsSMTP(); // telling the class to use SMTP
            $mail->Host = "smtp.163.com"; // SMTP server
            $mail->SMTPDebug = 2;                     // enables SMTP debug information (for testing)
            // 1 = errors and messages
            // 2 = messages only
            $mail->SMTPAuth = true;                  // enable SMTP authentication
            $mail->Host = "smtp.163.com"; // 邮箱服务器地址
            $mail->Port = 25;                    // 邮箱服务器端口
            $mail->Username = "1xxxxxxx@163.com"; // 你的邮箱用户名
            $mail->Password = "abcdefg@0";        // 你的邮箱密码
    
            $mail->SetFrom( '1xxxxxxx@163.com', '小----洋 ' );  //发送人
    
            //$mail->AddReplyTo( "2xxxxxxxx@qq.com", "亲" );    //接收方
    
    
            $mail->Subject = "=?utf-8?B?" . base64_encode( "我是标题" ) . "?=";      //解决中文标题乱码问题  设置标题
    
            $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    
            $mail->MsgHTML( $body );
            $address = "sheapchen@163.com";
            $mail->AddAddress( $address, "John Doe" );
    
            //$mail->AddAttachment( "附件1" );      // attachment      //这里可以添加附件
            // $mail->AddAttachment( "附件2" ); // attachment      
    
            if ( !$mail->Send() ) {
                echo "Mailer Error: " . $mail->ErrorInfo;
            } else {
                echo "Message sent!";
            }
            ?>
    
        </body>
    </html>
    
  • 相关阅读:
    apache安全—用户访问控制
    hdu 3232 Crossing Rivers 过河(数学期望)
    HDU 5418 Victor and World (可重复走的TSP问题,状压dp)
    UVA 11020 Efficient Solutions (BST,Splay树)
    UVA 11922 Permutation Transformer (Splay树)
    HYSBZ 1208 宠物收养所 (Splay树)
    HYSBZ 1503 郁闷的出纳员 (Splay树)
    HDU 5416 CRB and Tree (技巧)
    HDU 5414 CRB and String (字符串,模拟)
    HDU 5410 CRB and His Birthday (01背包,完全背包,混合)
  • 原文地址:https://www.cnblogs.com/sheapchen/p/3361930.html
Copyright © 2011-2022 走看看