CodeIgniter Forums
Email Library Modified - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Email Library Modified (/showthread.php?tid=38307)



Email Library Modified - El Forum - 02-04-2011

[eluser]Unknown[/eluser]
The email library in code igniter does not have an option to set name in the to address. I have added a code where the names can be passed as an array to the to function as an array with respect to the email address specified in the to parameter of the function.

You can just replace the to function with the below code:

function to($to,$to_name=array())
{
$to = $this->_str_to_array($to);
$to = $this->clean_email($to);

if ($this->validate)
{
$this->validate_email($to);
}
$temp_to = "";
if(is_array($to_name))
{
foreach($to_name as $key => $value)
$temp_to .= $value . "<" . $to[$key] . ">,";
}
if(strlen($temp_to) > 0)
$temp_to = substr($temp_to,0,-1);
else
$temp_to = implode(",", $to);

if ($this->_get_protocol() != 'mail')
{
$this->_set_header('To', $temp_to);
}

switch ($this->_get_protocol())
{
case 'smtp' : $this->_recipients = $temp_to;
break;
case 'sendmail' : $this->_recipients = $temp_to;
break;
case 'mail' : $this->_recipients = $temp_to;
break;
}
}