Welcome Guest, Not a member yet? Register   Sign In
Why Email foreach does not loop?
#1

Hi guys Why does loop

PHP Code:
<?php 
namespace App\Controllers;
use 
App\Models\FormModel;
use 
CodeIgniter\Controller;

class 
SendMailController extends Controller
{

    public function 
index() 
    {
        return 
view('form_view');
    }

    function 
sendMail() { 
        
         
$email = \Config\Services::email();
        
        
$to='[email protected]';
        
$from $this->request->getVar('mailTo');
        
$subject $this->request->getVar('subject');      
        
$email->setTo($to);
        
$email->setFrom($from'Booking Email');       
        
$email->setSubject($subject);
        
    
        
        
        
$list= array(
            
'somo' => $this->request->getPost('somo'),
            
'message' => $this->request->getPost('message'),/*only output this*/
       
);
       
      foreach (
$list as $key => $value) {
          
/*not does not loop*/

        
$mass $key." : " $value "\n";
        
        
$email->setMessage($mass);
                

      } 
      
        
        if (
$email->send()) 
        {
           
           return 
redirect()->back()->with('success''Email successfully sent');

        }
        else 
        {
            
$data $email->printDebugger(['headers']);
            
print_r($data);
        }
         
           
$config['protocol'] = 'sendmail';
            
$config['mailPath'] = '/usr/sbin/sendmail';
            
$config['charset']  = 'iso-8859-1';
            
$config['wordWrap'] = true;
            
$config['mailtype'] = 'html';

           
$email->initialize($config);
 
    }
     
      
       



The output of the above code snippet does only shows:
Code:
message: blaaablaaa

and not does show:

Code:
somo: blaablaa

Where is wrong?
Do Codeigniter Before Do You!
yekrinaDigitals

Reply
#2

Before every foreach try to clear email first $email->clear()
Reply
#3

He's over writing setMessage every time through the foreach loop. After the loop he sends the email.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB