Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:44:34+00:00 2026-06-11T02:44:34+00:00

That’s it, how can I send an email in background with CakePHP, preferable using

  • 0

That’s it, how can I send an email in background with CakePHP, preferable using the out-of-the-box Email component?

EDIT: with in background I mean in another thread, or at least allowing the controller method to finish and send the response to the user. I want to run a function, return “OK” to the user and, after that, send an email.

If it’s not possible, how could I do it using the PHP mail function? (only if it’s a good approach)

Don’t know if it matters, but I’m using SMTP.

Thank you in advance.

EDIT 2: I’m trying to use the CakeEmail::deliver() method, as I read from the documentation that:

Sometimes you need a quick way to fire off an email, and you don’t necessarily want do setup a bunch of configuration ahead of time. CakeEmail::deliver() is intended for that purpose.

I’m trying this:

CakeEmail::deliver('myemail@mydomain.com', 'Test', 'Test',
                array('from' => 'localhost@localhost.com'), true);

But the mail is not actually being sent. Anyone has any hint on that method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:44:35+00:00Added an answer on June 11, 2026 at 2:44 am

    So “in the background” means you want to process the mail sending “out of band”. This is to give the user a quick response, and to be able to process slow operations like email sending after the user has feedback (or as you say, in a separate thread).

    There are a number of ways to achieve this, including:

    • Workers / message queues
    • Cron job

    The simplest way is probably to use a cron job that fires off every 15 or 30 seconds.

    My recommended approach is to look into workers and queues, and use something like 0mq or RabbitMQ to queue the request to send an email, and process that outside the request.

    If you want to do a cron job, rather than sending the email within the request the user has initiated, you would create a new model to represent your outbound email requests, and store that data into your database. Lets call this model Message for example.

    CREATE TABLE `messages` (
       `id` CHAR(36) NOT NULL PRIMARY KEY,
       `to` VARCHAR(255) NOT NULL,
       `from` VARCHAR(255) NOT NULL,
       `subject` VARCHAR(255) NOT NULL,
       `body` TEXT,
       `sent` TINYINT(1) NOT NULL DEFAULT 0,
       `created` DATETIME
    );
    

    Create a Console that grabs the Message model, and does a find for “unsent” messages:

    $messages = $this->Message->findAllBySent(0);
    

    Create yourself a send() method to simplify things, and process all unsent messages:

    foreach ($messages as $message) {
       if ($this->Message->send($message)) {
           // Sending was a success, update the database
           $this->Message->id = $message['Message']['id'];
           $this->Message->saveField('sent', 1, false);
       }
    }
    

    The implementation of the send() method on the Message model is up to you, but it would just pass the values from the passed in $message and shunt through to CakeEmail (http://api.cakephp.org/class/cake-email)

    Once that is done, you can just call the console from the command line (or from your cron).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That is the question. Background: C# Params In C#, you can declare the last
That's my program written in C++ (OOP): #include <iostream> #include <string> using namespace std;
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That might sound silly but can't do it myself :( Need your help guys.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That simple. Moving my layout into a fluid territory, working on scalable images. Using
I know there's a lot of other questions out there that deal with this
That is the problem, i need to track the mouse movements(and register what component
That's it. How can I get the old value of a textarea in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.