Craft CMS plugin route redirects to login when not logged into Craft I created a simple Craft plugin to allow for custom action URLs. Specifically, I have a path "actions/api/sendEmail" that hits a method in my plugin's controller. It sends an email from a contact form via Ajax.

This works perfectly when I'm logged into Craft in the browser. But if I am not logged in, Ajax hits the "actions/api/sendEmail" URL and then gets redirected to "/login". Is my plugin not set to be a public-facing, front-end plugin? I'm pretty new to Craft. I've read through a lot of the docs about plugins and routes but can't seem to find the answer.

Thanks in advance for any help!

Here's my plugin controller class file:

&lt;?php
namespace Craft;

class apiController extends BaseController {

  function actionSendEmail() {

    $name = $_POST['first_name'] . ' ' . $_POST['last_name'];
    $email_address = $_POST['email'];
    $phone = $_POST['phone'];
    $company = $_POST['company'];
    $title = $_POST['title'];

    $email = new EmailModel();

    $email-&gt;toEmail = 'luke@graftonstudio.com';
    $email-&gt;subject = 'Contact Form Submission';
    $email-&gt;htmlBody = '&lt;style&gt;div, p, h2 { font-family: "Helvetica Neue", "Helvetica", sans-serif; font-size: 14px; line-height: 22px; color: #4b4b4b; font-weight: 400; }&lt;/style&gt;
                                            &lt;div style="margin: 20px; padding: 20px 20px 26px; border: 1px solid #e6e6e6; box-shadow: inset 0 1px 0 #ffffff, 0 4px 2px -3px rgba(0,0,0,0.06); background: #f9f9f9;"&gt;
                                                &lt;h2 style="margin: 0 0 20px 0; font-size: 20px;"&gt;Contact Form Submission&lt;/h2&gt;
                                                &lt;strong&gt;Name:&lt;/strong&gt;&lt;br&gt;' . $name . '&lt;br&gt;&lt;br&gt;
                                                &lt;strong&gt;Email:&lt;/strong&gt;&lt;br&gt;' . $email_address . '&lt;br&gt;&lt;br&gt;
                                                &lt;strong&gt;Phone Number:&lt;/strong&gt;&lt;br&gt;' . $phone . '&lt;br&gt;&lt;br&gt;
                                                &lt;strong&gt;Company:&lt;/strong&gt;&lt;br&gt;' . $company . '&lt;br&gt;&lt;br&gt;
                                                &lt;strong&gt;Job Title:&lt;/strong&gt;&lt;br&gt;' . $title . '&lt;br&gt;&lt;br&gt;
                                            &lt;/div&gt;';

    craft()-&gt;email-&gt;sendEmail($email);

    // not returning anything at the moment
    echo json_encode(array());
  }

}
You need to explicitly allow allow anonymous access to your controller's action.

More info on how to do that here: http://buildwithcraft.com/docs/plugins/controllers#allowing-anonymous-access-to-actions