sending a basic mail with php mail() |
[eluser]virtualgadjo[/eluser]
Hi all, not exactly new to CI but this time i feel like a newb i'm desesperatly trying to send a simple mail from a website using CI email library (with protocol => mail) and i get the following error Quote:Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.when sending the same mail the "old" way with the basic Code: $headers = "From: ".utf8_decode($from)."\n"; any idea would be warmly welcome chris PS sorry, forgot to say CI 2.0.1...
[eluser]virtualgadjo[/eluser]
hi again, worked it out, probably in a dirty way but i'm eager to hear from you i've changed line 1540 in the email libray Code: if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) instead of Code: if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) and it works like a charm now... to be precise, safe_mode if off on my server and set on FALSE in the email library this line occurs if it's on FALSE, changing it into the same line as it it were on TRUE and everything works again, there is porbably something i haven't understood but... it works ! something else, the comment above the line speaks about sendmail... when we are in mail() mode, may be that could be a hint for you guys but sincerely i don't know, i never use sendmail hope it helps (and, nevermind, still eager to hear about a better/cleaner solution if there is one...) Have swing
[eluser]kenjis[/eluser]
Your server is safe mode, isn't it? You can check by phpinfo() or ini_get('safe_mode').
[eluser]virtualgadjo[/eluser]
hi Kenji, no, it isn't, i've checked before the modification but, actually, i knew it was not because it's one of the first things i check, this, magic_quotes, trans sid and register globals and i do not use a hoster on which i can put all this on off/0 (with htaccess or a custom php.ini) if ever it's on. I actually understood the if... in the library and, just to be sure, had a look at my phpinfo once more, but no, safe mode off, that's why i posted my correction here thanks for answering have swing
[eluser]kenjis[/eluser]
This seems to be not a CI problem. How about this PHP code? Code: $headers = "From: ".utf8_decode($from)."\n"; Or the last line: Code: $success = @mail($to, stripslashes(utf8_decode($sujet)), stripslashes(utf8_decode($body)), $headers, '-f' . $data['email']); If PHP error occures, what the error message?
[eluser]virtualgadjo[/eluser]
well, actually, i used the CI syntax Code: $config = array( and as it sent me this error Quote:Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.i tried using the raw php syntax (the one you quote) without the -f and everything worked ok (well, to be honest, i've been sending mail this way for more than 10 years... ) that made me think that my server was configured to send mails with the php mail function (once more to be exhautive on the subjet, i had it running very well in raw php before i decided to refactor the whole site in CI because i'm going to develop quite a complex CRM in it, so i knew mail() was working very well...) i must admit i was about to send the mail without using CI mail class but i don't like to give up things... and changing Code: $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])) Code: $this->_header_str here are my phpinfos about safe mode, local and master value Code: safe_mode Off Off to be complete, php 5.2.17 on an Apache 2.0 Handler/Linux of course i understand all this may sound a bit strange as i'm sure if CI dev set the mail function when safe mode is off, there must be a very good reason but... it doesn't work for me this way... now maybe i've forgotten something in my usage of the class, if so, i'd really glad to know thanks again for taking time about this have swing
[eluser]virtualgadjo[/eluser]
hi again, i've tried your syntax to see what happens Code: $success = mail($to, stripslashes(utf8_decode($sujet)), stripslashes(utf8_decode($body)), $headers, '-f' . $data['email']); without the @ for php to be able to send me errors, no error but no mail either it may be that the additional parameters aren't allowed on the server even if not using the safe mode or, if we refer to the manual (our best friend...) Quote:The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.because the website MX are not managed by the hoster but but google apps, this could have our users not being added as trusted ones to the send mail config in this case, i must not be the only one running into this problem as many companies are doing the same with their mails. the optional parameters being... optional particularly when it comes to this envelop thing with -f, i think i'll go without them Have swing |
Welcome Guest, Not a member yet? Register Sign In |