• php+mysql乱码、邮件发送等


    关于乱码的调试的方法:

    首先保证phpmyadmin中自己都是用的utf-8
    网页也要用utf-8 注意是编码,而不仅仅是改title

    下面是截取字符串和发送邮件的函数:发送邮件这个方法蛮好的,具体的phpmailer在自己的电脑里面有。

    
    /**
     * Created by PhpStorm.
     * User: onlythe
     * Date: 3/15/15
     * Time: 10:15 AM
     */
    @header("Content-type: text/html; charset=utf8");
    
    
    $name= $_POST['name'];
    //$name= "聂小涛";
    $phone= $_POST['phone'];
    //$phone= "18868103563";
    $email= $_POST['email'];
    //$email= "642704194@yeah.net";
    $address= $_POST['address'];
    //$address= "浙江大学";
    
    //$week=["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    //
    //echo($week[0]);
    
    $year=date("Y");
    $month=date("m");
    $date=date("d");
    //$name3="聂小涛";
    $time=$year."年".$month."月".$date."日";
    $phone2=substr_replace($phone,"****",3,4);
    mb_internal_encoding("UTF-8");
    $name2=mb_substr($name,0,1)."老师";
    
    $auto=$name2." "." "." ".$phone2."    "."您的订单于".$time."订购成功,我们正在处理,谢谢!";
    //$auto=mysql_real_escape_string($auto);
    
    require_once 'conflg.php';
    
    $conn=mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PW);
    
    
    mysql_select_db('qdm134597118_db',$conn); //第二项目有默认。
    
    
    mysql_query("SET NAMES 'utf8';");
    mysql_query("INSERT INTO  form(info) VALUES ('$auto');");
    
    
    echo $auto;
    
    // mail("onlythen@yeah.net",
    //     "Visitor request for info."," 姓名".$name."电话".$phone."邮件".$email."地址".$address);
    
    // require("smtp.php");
    // //使用163邮箱服务器
    // $smtpserver = "smtp.163.com";
    // //163邮箱服务器端口
    // $smtpserverport = 25;
    // //163服务器邮箱账号
    // $smtpusermail = "onlythen@yeah.net";
    // //收件人邮箱
    // $smtpemailto = "caifuliuqj@163.com";
    // //邮箱账号(去掉@163.com)
    // $smtpuser = "caifuliuqj";//SMTP服务器的用户帐号
    // //邮箱密码
    // $smtppass = "***********"; //SMTP服务器的用户密码
    
    // //邮件主题
    // $mailsubject = "测试邮件发送";
    // //邮件内容
    // $mailbody = " 姓名".$name."电话".$phone."邮件".$email."地址".$address;
    // //邮件格式(HTML/TXT),TXT为文本邮件
    // $mailtype = "TXT";
    // //这里面的一个true是表示使用身份验证,否则不使用身份验证.
    // $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
    // //是否显示发送的调试信息
    // $smtp->debug = TRUE;
    // //发送邮件
    // $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
    
    
    $info=" 姓名".$name."电话".$phone."邮件".$email."地址".$address;
    
    include("phpmailer/class.phpmailer.php");
    
    class Mail
    {
        private $host = 'smtp.yeah.net';
        private $port = 25;
        private $username = 'onlythen@yeah.net';
        private $password = '*********';
    
        public function send($address, $info)
        {
            $mail = new PHPMailer;
            $mail->isSMTP();
            $mail->SMTPAuth = true;
            $mail->SMTPKeeyAlive = true;
            $mail->Host = $this->host;
            $mail->Port = $this->port;
            $mail->Username = $this->username;
            $mail->Password = $this->password;
            $mail->From = $this->username;
            $mail->FromName = '招生信息';
            $mail->Subject = '招生订单';
            $mail->Body = $info;
            $mail->AltBody = "您的验证码为${code}";
            $mail->WordWrap = 50;
            $mail->addAddress($address);
            $mail->isHTML(true);
            return $mail->send();
        }
    }
    
    $mail= new Mail();
    $mail->send("net@zju.edu.cn",$info);
    
    
    //if(mysql_errno()){echo mysql_error();}
    //else {
    //    echo "<script language="JavaScript">
    ";
    //    echo " location.assign("index.html");
    ";
    //    echo "</script>";
    //}
    //?
    
    if(mysql_errno()){echo mysql_error();}
    else {
       echo "<script language="JavaScript">
    ";
       echo " location.assign("index.html");
    ";
       echo "</script>";
    }
    ?>
  • 相关阅读:
    开通了
    A computer hardware platform abstraction
    脑机接口入门概览
    JDK自带VM分析工具jps,jstat,jmap,jconsole
    泛型里的super和extend
    动态规划
    用二分法查找的套路(一)
    A computer hardware platform abstraction
    CentOS7安装JDK1.8
    CentOS7如何修改hostname
  • 原文地址:https://www.cnblogs.com/zjunet/p/4559935.html
Copyright © 2020-2023  润新知