2015-09-21 94 views
0

我寫這個代碼從下面的查詢電子郵件,但它給了我一個錯誤:笨查詢提供了錯誤

undefined variable email

似乎從該查詢生成的結果不能被外面看到的foreach循環,但我想要那個電子郵件變量。該錯誤是在send_session_close_mail()功能:

$qry="select email from end_employee_master where 
     id=(select eemp_id from book_e_counseling_mst where CaseId='EC-".$cid."')" ; 

$query=$this->db->query($qry); 
$num=$query->num_rows(); 
foreach($query->result() as $row) { 
    $email=$row->email; 
} 

全部代碼:

<?php 

    class Email_model extends CI_Model { 

    private $config = null; 

    public function __construct() { 
     parent::__construct(); 
     $this->load->helper(array('form', 'url')); 
     $this->load->library('email'); 
     $this->config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'mail.santulan.co.in', 
      'smtp_port' => 25, 
      'smtp_user' => '[email protected]', // change it to yours 
      'smtp_pass' => '[email protected]', // change it to yours 
      'mailtype' => 'html', 
      'charset' => 'iso-8859-1', 
      'wordwrap' => TRUE 
     ); 
     $this->email->initialize($this->config); 
    } 

    public function send_password_reset_mail($new_pass, $email) { 
     $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Hello there,</span></p> 
         <p><span style="font-family: \'Tahoma\',Tahoma; font-weight:normal;">You have requested to reset your password. Please click on the below link. </span></p> 
         <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;"><a href="' . $base_url . 'index.php/login/reset_password?id=' . $new_pass . '" target="_blank">Click here</a></span></p> 
         <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Please do not share this link with anyone else.</span></p> 
         <p>&nbsp;</p> 
         <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Sincerely,</span></p> 
         <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Team Santulan&nbsp;</span></p> 
         <p><br /> 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject('Message From Santulan: Password Reset Link'); 
     $this->email->message($message_str); 
     $this->email->send(); 
    } 

    /** 

    function to change the password of the team 
    **/ 
    public function send_password_reset_mail_team($new_pass, $email) { 
     $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Hello there,</span></p> 
         <p><span style="font-family: \'Tahoma\',Tahoma; font-weight:normal;">You have requested to reset your password. Please click on the below link. </span></p> 
         <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;"><a href="' . $base_url . 'index.php/login/reset_password_team?id=' . $new_pass . '" target="_blank">Click here</a></span></p> 
         <p><span style="font-family: \'Tahoma\', Tahoma; font-weight:normal;">Please do not share this link with anyone else.</span></p> 
         <p>&nbsp;</p> 
         <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Sincerely,</span></p> 
         <p><span style="font-weight:normal; font-family: \'Tahoma\', Tahoma;">Team Santulan&nbsp;</span></p> 
         <p><br /> 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject('Message From Santulan: Password Reset Link'); 
     $this->email->message($message_str); 
     $this->email->send(); 
    } 

    /** 
    * Send mail to Counselor that Conversation has been 
    * updated by User for the E-Counseling case. 
    * @param type $data About case ID description etc. 
    */ 
    public function set_EC_notify_mail_counselor($data) { 
     $this->load->model('users'); 
     $userdata = $this->users->get_end_employee_Detail($data['eemp_id']); 
     $counselordata = $this->users->get_counselor_Detail($data['counseler_id']); 
     if ($userdata && $counselordata) { 
      $mailSubject = "E-Counseling Conversation Reply for Case ID " . $data['CaseId'] . "."; 
      $mailBody = '<p>Hi ' . $counselordata->name . ',</p> 
        <p>Greeting for the day.</p> 
        <p>You have new reply for the E-Counseling Case ID ' . $data['CaseId'] . 
        ' feedback conversation. This reply is from employee ' . $userdata->name . ' ' . 
        $userdata->lname . 
        '. Please login to <a href="http://www.santulan.co.in" target="_blank" title="http://www.santulan.co.in" name="http://www.santulan.co.in">http://www.santulan.co.in</a> to respond this.</p> 
        <p>&nbsp;</p> 
        <p><span style="font-weight:normal;">Thanks &amp; Regards,</span></p> 
        <p><span style="font-weight: normal;">Santulan Support Team</span></p>'; 
      $this->email->initialize($this->config); 
      $this->email->from('[email protected]', 'Santulan Suport Team'); 
      $this->email->to($counselordata->email); 
      $this->email->subject($mailSubject); 
      $this->email->message($mailBody); 
      $this->email->send(); 
     } 
    } 

    /** 
    * Send mail to Counselor that Conversation has been 
    * updated by User for the E-Counseling case. 
    * @param type $data About case ID description etc. 
    */ 
    public function set_EC_notify_mail_endUser($data) { 
     $this->load->model('users'); 
     $userdata = $this->users->get_end_employee_Detail($data['eemp_id']); 
     $counselordata = $this->users->get_counselor_Detail($data['counseler_id']); 
     if ($userdata && $counselordata) { 
      $mailSubject = "E-Counseling Conversation Reply for Case ID " . $data['CaseId'] . "."; 
      $mailBody = '<p>Hi ' . $userdata->name . ' ' . 
        $userdata->lname . ',</p> 
        <p>Greeting for the day.</p> 
        <p>You have new reply for the E-Counseling Case ID ' . $data['CaseId'] . 
        ' feedback conversation. This reply is from Counselor ' . $counselordata->name . 
        '. Please login to <a href="http://www.santulan.co.in" target="_blank" title="http://www.santulan.co.in" name="http://www.santulan.co.in">http://www.santulan.co.in</a> to respond this.</p> 
        <p>&nbsp;</p> 
        <p><span style="font-weight:normal;">Thanks &amp; Regards,</span></p> 
        <p><span style="font-weight: normal;">Santulan Support Team</span></p>'; 
      $this->email->initialize($this->config); 
      $this->email->from('[email protected]', 'Santulan Suport Team'); 
      $this->email->to($counselordata->email); 
      $this->email->subject($mailSubject); 
      $this->email->message($mailBody); 
      $this->email->send(); 
     } 
    } 

    public function send_feedback_mail($case_id, $emailID, $fname, $lname) { 
     $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<pre><em><strong>hello $fname end user why you want feedback from me cant you call me or you dont hav' 
       . ' enough balance in your phone. clik on the link below http://www.santulan/feedback/feedback_form?case_id=EC-12&emp_id=2&c_id</strong></em></pre>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($emailID); 
     $this->email->subject('Santulan-Feedback Email'); 
     $this->email->message('$message_str'); 
     $email->send(); 
    } 

    /**public function send_session_details($output) { 
     $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $case_id = $output['CaseId']; 
     $sessionDetail = $output['currentSessionDetails']; 


     $query = " SELECT email FROM end_employee_master WHERE id=(SELECT eemp_id FROM book_e_counseling_mst WHERE CaseId='$case_id')"; 
     $result = $this->db->query($query); 
     foreach ($result->result() as $row) { 
      $mail_id = $row->email; 
     } 
     $message_str = '<pre><em><strong>Hello counseler you have new case</strong></em></pre>'; 
     $this->email->from('[email protected]', 'Santulan Team'); 
     $this->email->to($mail_id); 
     $this->email->subject('Counselor you have new case come on'); 
     $this->email->message($message_str); 
     $this->email->send(); 
    }**/ 

    public function send_helpline_registration_mail($gvfcode,$data,$password) { 
     $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $email = $data['email']; 
     $firstname = $data['name']; 
     $lastname = $data['lname']; 
     $pass = $password; 
     $url = 'http://www.santulan.co.in/registration/verification/' . $gvfcode; 
     $message = "Dear $firstname $lastname, \n " . 
     '<p dir="ltr" style="color: rgb(34, 34, 34); font-family:Tahoma, Tahoma; font-size: 14 background-color: rgb(255, 255, 255);"> 
      Thank you for reaching out to SANTULAN. Please activate your account by clicking on the below link.</p> 
     <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);"> 
      <!---<strong>You can take counselling via phone or face 2 face</strong></p>---> 
     <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);"> 
     <!---<strong>For more details contact or Helpline no.</p>---> 
     <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);"> 
      <!---<strong>Also you can activate your account by clicking below link</p>---> 
       <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; fon background-color: rgb(255, 255, 255);"> 
      <a href="' . $url .'"><b>' . $url .'</b></a></p> 
     <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);"> 
      Your login id is your email address : ' . $email . '</p> 
     <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);"> 

Your password is : 
' . $pass . '</p> 
     <p dir="ltr" style="color: rgb(34, 34, 34); font-family: Tahoma, Tahoma; background-color: rgb(255, 255, 255);"> 
      <em>Thank you,<br /> 
      Team&nbsp;Santulan&nbsp;</em></p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to(trim($email)); 
     $this->email->subject('Registration Confirmation'); 
     $this->email->message($message); 
     $this->email->send(); 
    } 


    /** 
    Function to send email form submitted mail for E-counseling 
    **/ 

    public function send_mail_to_user($email) 
     { 
       $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<p> Hello There'. 
         '<br>'. 
       '<br>We have received your request. We will be in touch shortly'. 
       '<br>'. 
       '<br>Team Santulan 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject('Message From Santulan: You filled a form for E-Counseling'); 
     $this->email->message($message_str); 
     $this->email->send(); 

    } 


    /** 
    Function to send email form submitted mail for Telephonic-counseling 
    **/ 

    public function send_mail_to_tele_user($email) 
     { 
       $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<p> Hello There'. 
         '<br>'. 
       '<br>We have received your request. We will be in touch shortly'. 
       '<br>'. 
       '<br>Team Santulan 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject('Message From Santulan: Your Counseling Appointment'); 
     $this->email->message($message_str); 
     $this->email->send(); 

    } 


     /** 
    Function to send email form submitted mail for F to F-counseling 
    **/ 

    public function send_mail_to_ftof_user($email) 
     { 
       $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<p> Hello There'. 
       '<br>We have received your request. We will be in touch shortly'. 
       '<br>'. 
       '<br>Team Santulan 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject('Message From Santulan: Your Counseling Appointment'); 
     $this->email->message($message_str); 
     $this->email->send(); 

    } 




     /** 
    Function to send email form submitted mail for video - counseling 
    **/ 

    public function send_mail_to_video_user($email) 
     { 
       $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str ='<p> Hello There'. 
        '<br>'. 
       '<br>We have received your request. We will be in touch shortly'. 
       '<br>'. 
       '<br>Team Santulan 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject('Message From Santulan: Your Counseling Appointment'); 
     $this->email->message($message_str); 
     $this->email->send(); 

    } 

    /** 
     public function send_mail_fs() 
    { 

     $userid = $this->session->all_userdata(); 
     $email = $userid['logged_in']['email']; 
       $base_url = base_url(); 
     $this->email->initialize($this->config); 
     $message_str = '<p>Hello There,<br> 
     You have new case for assignment,please login and assighn it to counselor. 
           </p>'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is first support mail"); 
     $this->email->message($message_str); 
     $this->email->send(); 
    } 

    **/ 

    public function send_counselor_mail($email) 
    { 
     $this->email->initialize($this->config); 
     $message_str = 'Hello this is mail for counselor testing'; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to("[email protected]"); 
     $this->email->subject("This is first support mail"); 
     $this->email->message($message_str); 
     $this->email->send(); 
    } 


    /** 

    Function to send mail to enduser thatb session is closed 
    **/ 
public function send_session_close_mail($session_id,$c_type,$cid) 
    { 
      //$url = 'https://www.surveymonkey.com/r/?sm=s8ma655VB3Jd39QMaNl2YPaVWsbL3XPHrBW6ryEbhkGruBuQ8SLyNsX3hY6gwgopkuIJdbQy0GrI%2fPd77ydWOSP4R%2fOxaHLr52uARCuMiLg%3d'; 
     if($c_type=='E_Counseling') 
     { 
      $qry="select email from end_employee_master where id=(select eemp_id from book_e_counseling_mst where CaseId='EC-".$cid."')" ; 
      $query=$this->db->query($qry); 
      $num=$query->num_rows(); 


      foreach($query->result() as $row) 
      { 

       $email=$row->email; 
      } 

     $this->email->initialize($this->config); 
     $message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> '; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is mail from counselor"); 
     $this->email->message($message_str); 
     $this->email->send(); 
     } 
     if($c_type=='Telephone_Counseling') 
     { 
      $qry="SELECT email FROM book_tele_counseling_mstr WHERE CaseId like 'TC-" . $cid . "'"; 
    $query=$this->db->query($qry); 
    $num=$query->num_rows(); 


      foreach($query->result() as $row) 
      { 
       //$eemp_id=$row->eemp_id; 
       $email=$row->email; 
      } 

     $this->email->initialize($this->config); 
    $message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> '; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is mail from counselor"); 
     $this->email->message($message_str); 
     $this->email->send(); 


      } 
    if($c_type=='F2F_Counseling') 
     { 
        $qry="SELECT email FROM book_ff_counseling_mstr WHERE CaseId like 'FC-" . $cid . "'"; 
    $query=$this->db->query($qry); 
    $num=$query->num_rows(); 




      foreach($query->result() as $row) 
      { 
       //$eemp_id=$row->eemp_id; 
       $email=$row->email; 
      } 

     $this->email->initialize($this->config); 
      $message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> '; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is mail from counselor"); 
     $this->email->message($message_str); 
     $this->email->send(); 
     } 
     if($c_type=='Video_Counseling') 
     { 

      $qry="SELECT email FROM book_vedio_counseling_mstr WHERE CaseId like 'VC-" . $cid . "'"; 
      $query=$this->db->query($qry); 
      $num=$query->num_rows(); 


      foreach($query->result() as $row) 
      { 
       //$eemp_id=$row->eemp_id; 
       $email=$row->email; 
      } 

     $this->email->initialize($this->config); 
      $message_str = 'Your session for'.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> '; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is mail from counselor"); 
     $this->email->message($message_str); 
     $this->email->send(); 
     } 


    } 

} 
+0

線錯誤 –

+0

339和340線數的數量,其電子郵件可變THR在send_session_close_mail()函數 –

+0

PLZ在您所提供的代碼指定 –

回答

0

根據您的評論339和340行號就顯示錯誤,它的電子郵件變量存在於send_session_close_mail() 接下來是你的代碼:

 foreach($query->result() as $row) 
      { 

       $email=$row->email; 
      } 

     $this->email->initialize($this->config); 
     $message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> '; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is mail from counselor"); 
     $this->email->message($message_str); 
     $this->email->send(); 

我才知道要發送郵件到多個電子郵件ID作爲你foreach循環。並在loop變量電子郵件宣佈。

我建議你把所有sendding電子郵件的代碼在loop只有如下,並嘗試一次

foreach($query->result() as $row) 
    { 

       $email=$row->email; 


     $this->email->initialize($this->config); 
     $message_str = 'Your session for '.$c_type.'is closed,your case id is '.$cid.' please click on the link <a href="https://www.surveymonkey.com/r/NNLK2R2">Click Here</a> '; 
     $this->email->from('[email protected]', 'Santulan Suport Team'); 
     $this->email->to($email); 
     $this->email->subject("This is mail from counselor"); 
     $this->email->message($message_str); 
     $this->email->send(); 
    } 

這樣可以解決您的問題。

+0

的輸出,但它可能會發送電子郵件次數的循環遍歷 –