Home  >  Article  >  Backend Development  >  PHP怎么发邮件

PHP怎么发邮件

WBOY
WBOYOriginal
2016-06-13 13:33:20800browse

PHP如何发邮件?
sendMail.php中代码如下:

PHP code

<?php include_once './lib/class.phpmailer.php';
    class ToolKit
    {
        //发送邮件
        public static function mail($to,$subject,$content){                
            $mail = new PHPMailer();//实例化phpmailer   
            $address = $to;//接收邮件的邮箱   
            $mail->IsSMTP(); // 设置发送邮件的协议:SMTP   
            $mail->Host = "email.163.com"; // 发送邮件的服务器   
            $mail->SMTPAuth = true; // 打开SMTP   
            $mail->Username = "xxxx@163.com"; // SMTP账户      /*在这里填上发信的账户和密码*/
            $mail->Password = "xxxx"; // SMTP密码   
            $mail->From = "";   
            $mail->FromName = "";   
            $mail->AddAddress("$address", "");    
            $mail->CharSet = "UTF-8";//设置字符集编码   
            $mail->Subject = $subject;   
            $mail->Body = $content;//邮件内容(可以是HTML邮件)   
            $mail->AltBody = $content;   
            
            return $mail->Send();
        }
        
        //产生随机字符串(长度为$len,字母为小写)
        public static function random($len){
            $baseStr = "abcdefghijklmnopqrstuvwxyz1234567890";
            //mt_srand();
            $strs="";
            for($i=0;$i



运行后总是提示“ailed to connect to mailserver at "localhost" port 25”该怎样改?

------解决方案--------------------
$mail->Host = "smtp.163.com";
------解决方案--------------------
没有邮件服务 所以你得安装或者正确的配置好一个SMTP服务端
------解决方案--------------------
如果你是本地服务器上测试,需要安装IIS的那个什么邮件相关的东西。。。
------解决方案--------------------
PHP code
ToolKit::mail('xxxx@qq.com','test','test'); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn