程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 在codeigniter的helper用phpmailer 發送郵件

在codeigniter的helper用phpmailer 發送郵件

編輯:關於PHP編程

然後在helper文件裡 寫入如下函數

[php] 
function send_mail($to,$title,$body) 

    $ci =& get_instance(); 
    require_once('phpmailer/class.phpmailer.php'); 
    require_once('phpmailer/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       = $ci->config->item('mail_smtp'); // SMTP server  
      $mail->SMTPDebug  = false;                     // enables SMTP debug information (for testing)  
      $mail->SMTPAuth   = true;                  // enable SMTP authentication  
      $mail->Port       = $ci->config->item('mail_port');                    // set the SMTP port for the GMAIL server  
       
      $mail->Username   = $ci->config->item('mail_address'); // SMTP account username  
      $mail->Password   = $ci->config->item('mail_passwd');        // SMTP account password  
       
      $mail->AddAddress(www.2cto.com, ''); 
      $mail->SetFrom($ci->config->item('mail_address'), $ci->config->item('mail_name')); 
      
      $mail->Subject = $title; 
      $mail->MsgHTML($body); 
       
      $mail->Send(); 
      return true; 
    } catch (phpmailerException $e) { 
      //echo $e->errorMessage(); //Pretty error messages from PHPMailer  
      return false; 
    } catch (Exception $e) { 
      //echo $e->getMessage(); //Boring error messages from anything else!  
      return false; 
    } 
         

function send_mail($to,$title,$body)
{
 $ci =& get_instance();
 require_once('phpmailer/class.phpmailer.php');
 require_once('phpmailer/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       = $ci->config->item('mail_smtp'); // SMTP server
   $mail->SMTPDebug  = false;                     // enables SMTP debug information (for testing)
   $mail->SMTPAuth   = true;                  // enable SMTP authentication
   $mail->Port       = $ci->config->item('mail_port');                    // set the SMTP port for the GMAIL server
  
   $mail->Username   = $ci->config->item('mail_address'); // SMTP account username
   $mail->Password   = $ci->config->item('mail_passwd');        // SMTP account password
  
   $mail->AddAddress(www.2cto.com, '');
   $mail->SetFrom($ci->config->item('mail_address'), $ci->config->item('mail_name'));
 
   $mail->Subject = $title;
   $mail->MsgHTML($body);
  
   $mail->Send();
   return true;
 } catch (phpmailerException $e) {
   //echo $e->errorMessage(); //Pretty error messages from PHPMailer
   return false;
 } catch (Exception $e) {
   //echo $e->getMessage(); //Boring error messages from anything else!
   return false;
 }
  
}
另外在config裡寫入你的郵箱配置項

[php] 
$config['mail_name']='焦常雲'; 
$config['mail_passwd']='password'; 
$config['mail_address']='[email protected]'; 
$config['mail_smtp']='smtp.21cn.com'; 
$config['mail_smtp_port']=25; 
$config['mail_name']='焦常雲';
$config['mail_passwd']='password';
$config['mail_address']='[email protected]';
$config['mail_smtp']='smtp.21cn.com';
$config['mail_smtp_port']=25;

 作者:jiaochangyun
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved