Welcome Guest, Not a member yet? Register   Sign In
Email library - Setting "from" via config.
#1

[eluser]TheFuzzy0ne[/eluser]
Hi everyone. I'd like to set my default Emailer settings using a config array, but looking at the from() method, if I supply a string like this:

Admin <[email protected]>

The Email address is extracted, but the name is ignored.

Is there any way for me to get around this without having to call from() manually? I can override the from() method if necessary, but I just wanted to ensure I wasn't missing something painfully obvious.
#2

[eluser]pistolPete[/eluser]
Where do you want to store the default email settings?
Don't you have to call
Code:
from('[email protected]', 'Your Name');
before sending the mail? I don't really get why you would avoid calling from().
#3

[eluser]TheFuzzy0ne[/eluser]
It would be in the configuration file. This is the intialize() method from the Email class:
Code:
function initialize($config = array())
    {
        $this->clear();
        foreach ($config as $key => $val)
        {
            if (isset($this->$key))
            {
                $method = 'set_'.$key;

                if (method_exists($this, $method))
                {
                    $this->$method($val);
                }
                else
                {
                    $this->$key = $val;
                }    
            }
        }
        
        $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;    
        $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE;
    }


As you can see, if I set something like this:
Code:
$config['from'] = 'Admin <[email protected]>';

The string will be passed over to the from() method, and processed by it. I'm trying to avoid repeating calls to from() and reply_to() as I feel I should be able to just set them in my config file, and be done with it.

I guess I should just stick with calling it manually, I just figured that seeing as the Email library supported this feature, I should be able to use it.
#4

[eluser]pistolPete[/eluser]
Code:
(...) $method = 'set_'.$key; (...)
But there is no method named set_from()?
#5

[eluser]TheFuzzy0ne[/eluser]
Haha! I completely missed that line... Thanks for pointing that out, you've saved me a bit of a headache.




Theme © iAndrew 2016 - Forum software by © MyBB