2

I'm trying to send and email from a custom add-on using the Email Class and having no luck at all. I'm not totally sure how to debug this, as I've not got any server errors or anything like that.

This is the code I'm using as per the Docs:

$this->EE->load->library('email');
$this->EE->load->helper('text');

$this->EE->email->initialize();
$this->EE->email->wordwrap = true;
$this->EE->email->mailtype = 'text';
$this->EE->email->from($this->from_address);
$this->EE->email->to($receipient);
$this->EE->email->subject($subject);
$this->EE->email->message(entities_to_ascii($email_msg));
$this->EE->email->Send();

Are there any special requirements with regard to permissions I should be adding? I've created a separate user in order to post to a specific channel and then send notification emails.

I'm working locally at the moment and I've tried sending an email from the CP and that worked out ok, so I guess my email config is all right. I was logged in as the admin though.

Any help gratefully received.

3 Answers 3

2

I would suggest to print the message by debugging with the code:

echo $this->EE->email->print_debugger();

Use this line of the code below:

$this->EE->email->send();

to see any server message.

1

I wouldn't rely on whether the email turns up in your inbox as a good way to tell whether it is being sent or not (even if it works from the EE communicate tab). Your code looks correct, and if there are no errors then it is most likely being sent fine.

The first thing I would do to troubleshoot is sign up for SendGrid (free for up to 200 emails per day), and enter their SMTP settings into EE. That way, you can look in their control panel and see every email that is being sent from your site (it also greatly increases the chances of your email being delivered, some really popular email providers such as Gmail will just plain block email from IP addresses they haven't seen before, or especially if another customer at your ISP has a record of sending spam).

0

After messing about for a few days trying to re-invent the wheel, I decided to throw in the towel and just use FreeForm. No idea why I didn't come to this conclusion sooner.

Moral of the story - Make sure there aren't Add-ons out there which already do what you are trying to accomplish. You may have to adapt slightly to the way the Add-on does things, but in the end it'll save you time and money!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.