CodeIgniter Forums
not able to send email - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: not able to send email (/showthread.php?tid=6545)

Pages: 1 2


not able to send email - El Forum - 03-03-2008

[eluser]bevans[/eluser]
I get the following error when trying to send an email using the Email Class:

A PHP Error was encountered
Severity: Warning
Message: mail() expects parameter 1 to be string, array given
Filename: libraries/Email.php
Line Number: 1341

Here are some details:
I am not using an array, I only pass one email address to the "to" field. There is no cc or bcc.

Here is the controllers info:
Code:
$this->load->library('email');
$this->email->from('[email protected]', 'my message');
$this->email->to($_POST['email']);
$this->email->subject('Please confirm your email');
$this->email->message('Thank you for registering...');
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
   if (!$this->email->send())
      {
         echo 'not able to send an email';
      }
$this->email->print_debugger();

What am I doing wrong, and how do I fix it?

Thanks in advance.


not able to send email - El Forum - 03-03-2008

[eluser]Michael Wales[/eluser]
Can you print_r the $_POST['email'] variable and let us know what it returns.


not able to send email - El Forum - 03-03-2008

[eluser]bevans[/eluser]
[quote author="Michael Wales" date="1204599584"]Can you print_r the $_POST['email'] variable and let us know what it returns.[/quote]


Yes,
When I use print_r($_POST['email']);
It prints out the email address I enter in the form.
In this case, I just used a dummy email address of "[email protected]" then when I click submit on the form. I get the email printed on the top of the screen just like it is: [email protected]

So the email address that gets passed to $_POST['email'] is the correct email.

Here is some background that I should have given sooner.
I have a registration form that people need to enter their name, email, username, and password. When they submit the form, I want to have CI send them an email stating that they have successfully registered.
The error that I get occurs when the form is submitted.


not able to send email - El Forum - 03-03-2008

[eluser]Pygon[/eluser]
well.. if | echo $_POST['email']; | is giving you the email address, you might try using a hardcoded email being passed to the $this->email->to() and see what happens.


not able to send email - El Forum - 03-03-2008

[eluser]bevans[/eluser]
[quote author="Pygon" date="1204600408"]well.. if | echo $_POST['email']; | is giving you the email address, you might try using a hardcoded email being passed to the $this->email->to() and see what happens.[/quote]

I have used a hard-coded email in place of $_POST['email'], but it still gives me the same error.

I am a little lost... is there a bug of some kind?


not able to send email - El Forum - 03-03-2008

[eluser]Pygon[/eluser]
Actually -- looking at it, it may be:

try this:

applications/libraries/MY_Email.php
Code:
<?php
class MY_Email extends CI_Email {

  function MY_Email(){
    parent::CI_Email();
  }

  function _send_with_mail()
  {    
    if ($this->_safe_mode == TRUE)
    {
      //Pygon: Added implode
      if ( ! mail(implode(', ',$this->_recipients), $this->_subject, $this->_finalbody, $this->_header_str))
        return FALSE;
      else
        return TRUE;        
    }
    else
    {
      // most documentation of sendmail using the "-f" flag lacks a space after it, however
      // we've encountered servers that seem to require it to be in place.
      //Pygon: Added implode
      if ( ! mail(implode(', ',$this->_recipients), $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
        return FALSE;
      else
        return TRUE;
    }
  }

?>

Not positive it will work, but worth a shot. (I don't have mail on my local webserver)

Drop it in and run the script again as is.


not able to send email - El Forum - 03-03-2008

[eluser]bevans[/eluser]
When I try that class you gave Pygon, I get this error now:

A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing
Filename: libraries/Email.php
Line Number: 1341

The php.ini file is set up.
Maybe something in it is wrong.
Here is what my php.ini file says:

[mail function]
; For Win32 only.
;This is the original setting >>> SMTP = localhost
; the following two lines are added for the godbit.com tutorial
; changed SMTP to: SMTP = localhost as indicated above, but it does not make a difference
SMTP = mail.yahoo.com
sendmail_from = bevans@yahoo.com
smtp_port = 25

; For Win32 only.
;sendmail_from = [email protected]

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path = "D:\XAMPP\sendmail\sendmail.exe -t"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =


not able to send email - El Forum - 03-03-2008

[eluser]mikeyhell[/eluser]
Can you send a simple mail?

Code:
mail('[email protected]', 'My Subject', 'testing');



not able to send email - El Forum - 03-04-2008

[eluser]bevans[/eluser]
[quote author="mikeyhell" date="1204618450"]Can you send a simple mail?

Code:
mail('[email protected]', 'My Subject', 'testing');
[/quote]


Negative. I cannot send a simple email using the mail() function.

It gives me an error that the php.ini file is not set up correctly. (see below)
I am beginning to think that it might be something with my local settings / machine, since I am still developing on my local machine.

Error message (same as above error I listed in posting #6):
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing
Filename: libraries/Email.php
Line Number: 1341


When I run a phpinfo(); function, I get this:
sendmail_from no value no value
sendmail_path no value no value
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25


not able to send email - El Forum - 03-04-2008

[eluser]Pygon[/eluser]
TBH, It seems that you're making php.ini file changes to the php.ini that is not being loaded (or the webserver has not been restarted since the change).

Regarding your first error, however, it seems that this might be a bug in CI, so i'll go ahead an post it for verification.