Welcome Guest, Not a member yet? Register   Sign In
Sending an Email does not seem to work
#1

[eluser]No0oB[/eluser]
Hey guys.
I have recently been struggling with the Email-Class of CodeIgniter.
When sending the email, I do not get any errors, in fact, it sais the the Email has been sent, however, I enver receive an email (just on google it works - no idea why..)

Following Code should send the Email. $userdata is a parameter given to the function in an own class.
Code:
$email_body = $this->CI->lang->line('user_register_email_header');
$email_body .= site_url().'/user/activate/'.dohash($this->CI->session->userdata('validation_email'), 'md5');
$email_body .= $this->CI->lang->line('user_register_email_footer');
        
$this->CI->load->library('email');
$this->CI->email->from(EMAIL_FROM_ADRESS, EMAIL_FROM_NAME);
$this->CI->email->to($userdata['user_email']);
$this->CI->email->subject($this->CI->lang->line('user_register_email_subject'));
$this->CI->email->message($email_body);
        
if (!$this->CI->email->send())
{
    return $this->CI->lang->line('error_email_sent').'<br /><br />'.$this->CI->email->print_debugger();
}

This is the Email-Body (Yeah, it is german, but that should not be the problem Smile )
Code:
$lang['user_register_email_header'] = 'Hallo und vielen Dank für die Registrierung bei dem Browsergame Atlantica!

Damit dieser Benutzer verwendet werden kann, muss auf folgenden Aktivierungslink geklickt werden.

';

Any advice?
#2

[eluser]Josh Kendall[/eluser]
What does the script output from the print debugger function? Does your server have PHP's MAIL installed? I know at work one of the servers doesn't, so that could be a possibility. Have you tried changing the protocol to sendmail or smtp?
#3

[eluser]No0oB[/eluser]
Thank you for your reply John.
Here is, what the debugger is returning:

Quote:From: "This Browsergame"
Return-Path:
Reply-To: "noreply@this_browsergame.com"
X-Sender: noreply@this_browsergame.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <47a477374cb77@this_browsergame.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Registrierung bei Atlantica
Hallo und vielen Dank für die Registrierung bei dem Browsergame Atlantica!

Damit dieser Benutzer verwendet werden kann, muss auf folgenden
Aktivierungslink geklickt werden.

http://bg.phpdave.com/index.php/user/act...490ecaa197

Is it normal that Return-Path is empty?

And no: I have not yet tried to change the protocol because I do not know why I should use which protocol Smile
#4

[eluser]Josh Kendall[/eluser]
No0oB, can you change your code from:

Code:
if (!$this->CI->email->send())
{
    return $this->CI->lang->line('error_email_sent').'<br /><br />'.$this->CI->email->print_debugger();
}

to

Code:
$this->CI->email->send()
return $this->CI->lang->line('error_email_sent').'<br /><br />'.$this->CI->email->print_debugger();

and see if the results of the print_debugger function is different. This way it always gives you the results of the message, and it should tell you that your message did one of two things.

1. Sent Successfully: "Your message has been successfully sent using the following protocol: mail"

2. The message failed, and a reason.

What you posted from the print_debugger function said neither of those things.
#5

[eluser]No0oB[/eluser]
I did it the way you üpropsed it, I just forgot to paste the first line.
I am very sorry abou that Smile

Quote:Ihre Botschaft ist erfolreich verschickt worden. Verwendetes Protokoll: mail

From: "This Browsergame"
Return-Path:
Reply-To: "noreply@this_browsergame.com"
X-Sender: noreply@this_browsergame.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <47a480587b5da@this_browsergame.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Registrierung bei Atlantica
Hallo und vielen Dank für die Registrierung bei dem Browsergame Atlantica!

Damit dieser Benutzer verwendet werden kann, muss auf folgenden
Aktivierungslink geklickt werden.

http://bg.phpdave.com/index.php/user/act...490ecaa197

The first line is your line, just in german.
#6

[eluser]Josh Kendall[/eluser]
Yeah, you don't appear to have PHP mail installed on your server. You could try Sendmail:

Code:
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

You may need to change the path to sendmail depending on your server.
#7

[eluser]No0oB[/eluser]
Ah I see.
So I have to initilize each time I want to send it or can I extend the Emailclass and put it into the constructor / send ?

Thank you very much for your help
#8

[eluser]Josh Kendall[/eluser]
If you look in the libraries/Email.php file on line 33 you will see:

Code:
var $protocol = "mail";// mail/sendmail/smtp

if you change that to:

Code:
var $protocol = "sendmail";// mail/sendmail/smtp

You probably won't need to add anything in your code as CI will default to Sendmail.
#9

[eluser]No0oB[/eluser]
Ok, thank you very much again
#10

[eluser]No0oB[/eluser]
One more question.
Why did I yet receive Emails with gmail? Big Grin

Edit:
Nevermind that, I still don't get Emails
Here is the phpinfo: http://bg.phpdave.com/info.php

I want to use the config-method
Quote:Setting Email Preferences in a Config File

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

Now, I do have a config file located at application/config/email.php with following contents

Code:
&lt;?php

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

?&gt;

Yet, the debugger tells me that the protocol I am using is mail....

Edit2:
The only way I got sendmail to work is to use the $config directly in CI with initializing the library.
So, it ended up showing sendmail, but I still dont get any email.
Seriously, what is going on?
I mean.. mail() works..




Theme © iAndrew 2016 - Forum software by © MyBB