php - $this->email->send() return false still email get send

737

I am sending notification email using code igniter email library. Email sending is working properly but sometime only.

I am using$this->email->send() to check that email is send or not. Like:

if($this->email->send())
{
    //Success
} else {
    // faile
print_r ( $this->email->print_debugger ( array ('headers','subject') )); 
}

Problem:

It sounds unreal but I have tested it many time before asking here. When I execute the code then in my system log it shows that email isUnable to send email using PHP SMTP. Your server might not be configured to send mail using this method. but When i check the email account then it has that email which my system log say failed. In short$this->email->send() is not working for me.

So can anyone suggest any other alternative solution for this problem.

I have also tried to debug it and it shows that it will came to ease and print the debug detail but while in this process email is get send.

In the debug process$this->email->send() returnFALSE but still email get send.

any suggestion regarding this will be appreciated.

275

Answer

Solution:

if sending email in a loop try

$this->email->clear();

before defining email variables

here is an example

foreach ($list as $name => $address)
{
        $this->email->clear();

        $this->email->to($address);
        $this->email->from('[email protected]');
        $this->email->subject('Here is your info '.$name);
        $this->email->message('Hi '.$name.' Here is the info you requested.');
        $this->email->send();
}

People are also looking for solutions to the problem: php - Wordpress | Custom post type loop with odd/even alternating

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.