Yii's use of built-in php mail not overidable?

Loving yii so far, but troubled with my first day of coding by something.

I see that there are a number of extensions for yii that interface with 3rd party mail scripts like phpmailer.

But it appears to me – and correct me if i’m wrong – that some of the core yii code (like the contact form code that is built when you create a new webapp), make direct explicit calls to the built-in php mail function.

And that there is no higher level mailing function that could be re-routed to different mailer classes.

If that is indeed the case I’d like to strongly encourage yii coders to change this, and make a standardized higher-level mail function that could then be routed to different mail classes. This is the behavior i’ve seen in similar frameworks, and the benefit in terms of code maintenance is huge – it makes it possible to swap the entire mail handling code from one library to another without having to change every single mail call in your own code and in the yii generated code to switch to a different mail function.

To summarize, I think having yii code make direct calls to the low level php built-in mail function is a mistake – it should call a generuc class or function that we can customize the handling of through extensions.

If i’m wrong and yii already supports this – let me know!

The code you are referring to (contact page) is not the core Yii framework code… that is the default code generated by Yii when creating a new webapp…

that code is just a skeleton and a sample… that should/must be changed to appropriate needs…

i still think the point i’m trying to make stands – there should be a higher level standardized wrapper for all emailing, that all code should call, which could then be replaced by extensions. rather than having everyone hard code specific mail calls or calls to different specific 3rd party mail extensions scattered all over their code.

Sending an email in php is 1 line of code.

If you want something of more complex, there are lot of extension for doing that, or you can write a widget that fits your specific needs.

P.s: welcome to the forum.

I couldn’t agree more with the replies given!

For the things you’re missing in Yii there are always extensions providing the functionality. Furthermore, Zend integrates very well, so you can easily use its mail functionality. But check out the mail extensions too, they are well explained and easy to use!!

cheers

There is.

It’s called ‘extension’.

This is actually a very nice feature of Yii because you’re free to either cook up your own, or choose one from the ever growing collection of Yii extensions.

It’s a design decision to not include everything but the kitchen sink in Yii. ;)

Let me try one last time to explain what I’m saying since everyone seems to be missing my point.

I’m not suggesting that any more sophisticated mail code be included with yii core.

I’m not disagreeing in any way with the use of extensions to provide more advanced mailing features.

What I am suggesting is that yii should provide a mail class that is easily CONFIGURABLE in the config file to use a different extension to do the mailing.

So that all code on a site can invoke the "yiimail" function when they need to send email, and this would be default use the built in php mail function, but could be overidden for all code by installing an extension and changing the config to use it as the mailer.

For example: Imagine i install 10 different 3rd party modules and extensions that all need to send mail… With the current way yii is set up, each of these 10 different authors have to make their own explicit decision to use the built-in php mail() function or else choose a specific mail extension to be dependent on – and they could all make different decisions. And if i want to switch over to an smtp mailer, i now have to go through all of this 3rd party code and manually change it… Very bad.

The solution is pretty straightforward – create a core class for mailing, that can be overidden in the config file (or some similar mechanism), so that all code can use this class (or function), and so that the user only needs change the main config file to have all modules/extensions/code now invole a different mailer.