Welcome Guest, Not a member yet? Register   Sign In
Email class - $this->email->message();
#1

[eluser]the_unforgiven[/eluser]
Instead of using:
Code:
$this->email->message('This is my message');

Is it possible to set an array then use:
Code:
$mymessage = array(
// then in this array I would like to get all the data from the form so would i use

$this->input->post('name'); //for example?

);

$this->email->message($mymessage);

I have tried this and got this error

Quote:Severity: Warning
Message: rtrim() expects parameter 1 to be string, array given
Filename: libraries/Email.php
Line Number: 383
#2

[eluser]CroNiX[/eluser]
No, message is the text of your email body. Obviously, no PHP can go in there. It needs to be plain text or html depending on your settings.

What exactly are you trying to do?
#3

[eluser]the_unforgiven[/eluser]
hi chronix

Im trying to get the whole form to send

heres my form:

Code:
<?php echo form_open('welcome/send'); ?>
    <fieldset>
     <ol>
      <li><label>Name:</label>&lt;input type="text" name="name" value="" /&gt;&lt;/li>
      <li><label>Email:</label>&lt;input type="text" name="email" value="" /&gt;&lt;/li>
      <li><label>Phone:</label>&lt;input type="text" name="phone" value="" /&gt;&lt;/li>
      <li><label>Address:</label>&lt;textarea name="address" rows="5" cols="20"&gt;&lt;/textarea></li>
      <li>&lt;input type="submit" name="submit" value="Send me a sample" class="btn" /&gt;&lt;/li>
     </ol>
    </fieldset>
   &lt;/form&gt;

here's controller

Code:
function send()
{
  // Set Validation Rules
  $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|xss_clean');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  $this->form_validation->set_rules('phone', 'Phone', 'trim|required|max_length[12]');
  $this->form_validation->set_rules('address', 'Address', 'trim|required|min_length[2]');
  
  // Validation runs false rteun back to form and show errors
  if ($this->form_validation->run() == FALSE) {
      
    $data['error'] = $this->session->set_flashdata('error', 'Sorry there where some errors');
    $this->load->view('home', $data);
  }
  // If everything is filled out with no errors proceed with sending the form to email and database
  else {
  $name = $this->input->post('name');  
  $email = $this->input->post('email');
  $message = array(
   $this->input->post('name'),
   $this->input->post('email'),
   $this->input->post('phone'),
   $this->input->post('address')

  );

  $this->email->from($email, $name);
  $this->email->to('[email protected]');
  $this->email->subject('Site Submission');
  $this->email->message('Someone has left a message', $message); // in this var i want to get the name email phone and address from the form
  $this->email->send(); // Send the message function to the persons email address
  $this->email->clear(); // Clears the form ready for another submission

  $this->email_model->insert_into_db();
  echo '[removed]
      alert("Thank You.\r\n\r\nWe have received your email and will be in touch shortly\r\n\r\nThis box will refresh in 4 seconds.");
      setTimeout(\'[removed].href = "index.php"\', 4100);
  [removed]';

  }
}
#4

[eluser]CroNiX[/eluser]
Well, you just need to create your single string of text that gets passed to email::message().
Code:
//$message = array(
//   $this->input->post('name'),
//   $this->input->post('email'),
//   $this->input->post('phone'),
//   $this->input->post('address')
//);

$message = $this->input->post('name') . "\n";
$message .= $this->input->post('email') . "\n";
$message .= $this->input->post('phone') . "\n";
$message .= $this->input->post('address');
#5

[eluser]the_unforgiven[/eluser]
or yes of course silly me, cheers chronix for clearing that up much appreciated once again.
#6

[eluser]the_unforgiven[/eluser]
and $this->email->message($message); would carry those strings through then?
#7

[eluser]the_unforgiven[/eluser]
I guess so all working fine thanx again Chronix




Theme © iAndrew 2016 - Forum software by © MyBB