### Install and Configure EmailQueue Source: https://context7.com/tin-cat/emailqueue/llms.txt Steps to clone the repository, install dependencies, set up the MySQL database, and configure application settings. ```bash git clone https://github.com/tin-cat/emailqueue.git cd emailqueue composer update # Create the database (MySQL) mysql -u root -p -e "CREATE DATABASE emailqueue;" mysql -u root -p emailqueue < install/emailqueue.sql # Copy and edit config files cp config/db.config.inc.php.example config/db.config.inc.php cp config/application.config.inc.php.example config/application.config.inc.php ``` -------------------------------- ### Cron Job Setup for EmailQueue Source: https://context7.com/tin-cat/emailqueue/llms.txt Commands to make scripts executable and examples for setting up cron jobs to deliver emails and purge old records. ```bash # Make scripts executable chmod +x scripts/delivery scripts/flush scripts/pause scripts/purge scripts/run scripts/unpause # Edit crontab crontab -e ``` ```cron # Deliver queued emails every minute * * * * * /var/www/emailqueue/scripts/delivery # Purge old sent emails daily at 6am 0 6 * * * /var/www/emailqueue/scripts/purge ``` -------------------------------- ### Application Configuration Example Source: https://context7.com/tin-cat/emailqueue/llms.txt Sets up API keys, frontend credentials, delivery tuning parameters, and SMTP settings for EmailQueue. ```php true` to bypass the queue and send emails immediately. This is suitable for time-critical messages. Ensure necessary configuration files are included. ```php inject([ "from" => "security@example.com", "from_name" => "Security Team", "to" => "user@example.com", "subject" => "Your password reset link", "is_html" => true, "content" => "

Click here to reset your password. This link expires in 15 minutes.

", "priority" => 1, // Highest priority "is_send_now" => true // Send right now, do not queue ]); if ($result) { echo "Password reset email sent immediately.\n"; } } catch (Exception $e) { echo "Delivery failed: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Pull Latest Version Source: https://github.com/tin-cat/emailqueue/blob/master/README.md Use this command to fetch the latest changes from the Emailqueue repository when upgrading. ```bash $ git pull ``` -------------------------------- ### Queue a Single Email with PHP Source: https://context7.com/tin-cat/emailqueue/llms.txt Use this method to insert a single email into the queue. All fields except 'from', 'to', and 'subject' are optional. Ensure configuration files are included and the Emailqueue class is instantiated. ```php inject([ // Internal tracking IDs (optional) "foreign_id_a" => 42, // e.g. your user ID "foreign_id_b" => 7, // e.g. your campaign ID // Delivery control "priority" => 10, // Lower = higher priority "is_immediate" => true, // Queue for next delivery run "is_send_now" => false, // true = bypass queue, send inline "date_queued" => strtotime("+2 hours"), // Scheduled delivery timestamp // Sender / recipient "from" => "noreply@example.com", "from_name" => "My App", "to" => "user@example.com", "replyto" => "support@example.com", "replyto_name" => "Support Team", "sender" => "bounces@example.com", // Return-path for bounces // Content "subject" => "Welcome to My App 🚀", "is_html" => true, "content" => "

Welcome!

Thanks for signing up.

", "content_nonhtml" => "Welcome! Thanks for signing up.", // Deliverability "list_unsubscribe_url" => "https://example.com/unsubscribe?token=abc123", // Attachments (local paths only; not supported via API) "attachments" => [ [ "path" => "/var/www/app/files/welcome.pdf", "fileName" => "Welcome Guide.pdf", // optional override "encoding" => "base64", // optional, default: base64 "type" => "application/pdf" // optional, auto-detected if omitted ] ], // Auto-embed tags as inline attachments "is_embed_images" => false, // Extra mail headers "custom_headers" => [ "X-Campaign-ID" => "summer2024", "X-Priority" => "1" ] ]); if ($result) { echo "Email queued successfully.\n"; } } catch (Exception $e) { echo "Failed to queue email: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Inject Single Email (PHP SDK) Source: https://context7.com/tin-cat/emailqueue/llms.txt Inserts one email into the queue using the PHP SDK. Accepts an associative array of message parameters. Returns true on success, throws an Exception on error. ```APIDOC ## `emailqueue_inject::inject()` — Queue a Single Email Inserts one email into the queue. Accepts an associative array of message parameters. Returns `true` on success, throws an `Exception` on error. All fields except `from`, `to`, and `subject` are optional. ### Parameters All fields within the message array are optional except for `from`, `to`, and `subject`. #### Message Fields - **foreign_id_a** (integer) - Optional - Internal tracking ID (e.g., your user ID). - **foreign_id_b** (integer) - Optional - Internal tracking ID (e.g., your campaign ID). - **priority** (integer) - Optional - Lower value indicates higher priority. Defaults to a system-defined value. - **is_immediate** (boolean) - Optional - If true, queue for the next delivery run. Defaults to false. - **is_send_now** (boolean) - Optional - If true, bypass the queue and send inline. Defaults to false. - **date_queued** (timestamp) - Optional - Scheduled delivery timestamp. Defaults to current time. - **from** (string) - Required - The sender's email address. - **from_name** (string) - Optional - The sender's display name. - **to** (string) - Required - The recipient's email address. - **replyto** (string) - Optional - The reply-to email address. - **replyto_name** (string) - Optional - The reply-to display name. - **sender** (string) - Optional - The sender address for bounces (Return-Path). - **subject** (string) - Required - The email subject. - **is_html** (boolean) - Optional - If true, the content is HTML. Defaults to false. - **content** (string) - Optional - The email body content. - **content_nonhtml** (string) - Optional - The plain text version of the email body. - **list_unsubscribe_url** (string) - Optional - URL for unsubscribing. - **attachments** (array) - Optional - An array of attachment objects. Each object can have: - **path** (string) - Required - Local path to the attachment file. - **fileName** (string) - Optional - Override for the attachment's filename. - **encoding** (string) - Optional - Encoding type (e.g., 'base64'). Defaults to 'base64'. - **type** (string) - Optional - MIME type of the attachment (auto-detected if omitted). - **is_embed_images** (boolean) - Optional - If true, auto-embed `` tags as inline attachments. Defaults to false. - **custom_headers** (array) - Optional - An associative array of custom email headers. ### Returns - `true` on success. - Throws an `Exception` on error. ### Example ```php inject([ "from" => "noreply@example.com", "to" => "user@example.com", "subject" => "Welcome to My App 🚀", "content" => "

Welcome!

Thanks for signing up.

", "is_html" => true, "priority" => 10, "foreign_id_a" => 42 ]); if ($result) { echo "Email queued successfully.\n"; } } catch (Exception $e) { echo "Failed to queue email: " . $e->getMessage() . "\n"; } ``` ``` -------------------------------- ### Clone Emailqueue Repository Source: https://github.com/tin-cat/emailqueue/blob/master/README.md Use this command to clone the Emailqueue repository to your desired location. Ensure it's not in a publicly accessible web directory. ```bash $ git clone https://github.com/tin-cat/emailqueue.git ``` -------------------------------- ### Scheduled Email Delivery with `date_queued` (PHP) Source: https://context7.com/tin-cat/emailqueue/llms.txt Schedule emails for future delivery by providing a Unix timestamp to `date_queued`. The delivery cron job will process these emails only after the specified time. Ensure configuration files are included. ```php inject([ "from" => "promotions@example.com", "from_name" => "My Shop", "to" => "customer@example.com", "subject" => "Your Monday morning deals!", "is_html" => true, "content" => "

This week's offers

Check out our latest deals...

", "priority" => 10, "date_queued" => $sendAt, // Hold until next Monday 9am "list_unsubscribe_url" => "https://example.com/unsubscribe" ]); if ($result) { echo "Email scheduled for " . date("Y-m-d H:i:s", $sendAt) . "\n"; } } catch (Exception $e) { echo "Scheduling failed: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Make Scripts Executable Source: https://github.com/tin-cat/emailqueue/blob/master/README.md Grant execute permissions to the necessary shell scripts within the scripts directory. This is required for cronjob execution. ```bash $ cd scripts $ chmod +x delivery flush pause purge run unpause ``` -------------------------------- ### Send Single Email via HTTP API using curl Source: https://context7.com/tin-cat/emailqueue/llms.txt Use this method to send a single email via the HTTP API when EmailQueue is running as a separate service or Docker container. Requires an API_KEY and a POST request with a JSON payload. ```bash curl -X POST https://emailqueue.example.com/api/ \ -d 'q={ "key": "your-secret-api-key-here", "message": { "from": "noreply@example.com", "from_name": "My App", "to": "user@example.com", "subject": "Hello from EmailQueue", "content": "Hello! This was sent via the API.", "is_html": true, "priority": 5, "list_unsubscribe_url": "https://example.com/unsubscribe" } }' # Response: {"result":true,"description":false} ``` -------------------------------- ### Inject Single Email via API Source: https://github.com/tin-cat/emailqueue/blob/master/README.md Send a single email by making an HTTP POST request to the Emailqueue API endpoint. The request body should contain a JSON object with an API key and a message object. ```APIDOC ## POST /emailqueue ### Description Inject a single email into the Emailqueue system via an HTTP POST request. ### Method POST ### Endpoint `https:///` (e.g., `https://192.168.1.100/emailqueue`) ### Parameters #### Request Body - **q** (json) - Required - A JSON object containing the API key and the email message details. - **key** (string) - Required - The API_KEY for authentication. - **message** (object) - Required - An object defining the email message. - **from** (string) - Required - Sender's email address. - **to** (string) - Required - Recipient's email address. - **subject** (string) - Required - Subject of the email. - **content** (string) - Required - Body of the email. ### Request Example ```json { "key":"your_api_key", "message": { "from":"me@domain.com", "to":"him@domain.com", "subject":"Just testing", "content":"This is just an email to test Emailqueue" } } ``` ### Response #### Success Response (200) - **result** (boolean) - True if the email was injected successfully, false otherwise. - **errorDescription** (string) - A description of the error, if any. #### Response Example ```json { "result": true, "errorDescription": null } ``` ``` -------------------------------- ### Inject Multiple Emails via API Source: https://github.com/tin-cat/emailqueue/blob/master/README.md Send multiple emails in a single API call by making an HTTP POST request. The request body should contain a JSON object with an API key and a 'messages' array. ```APIDOC ## POST /emailqueue ### Description Inject multiple emails into the Emailqueue system in a single API call via an HTTP POST request. ### Method POST ### Endpoint `https:///` (e.g., `https://192.168.1.100/emailqueue`) ### Parameters #### Request Body - **q** (json) - Required - A JSON object containing the API key and an array of email messages. - **key** (string) - Required - The API_KEY for authentication. - **messages** (array) - Required - An array of objects, where each object defines an email message. - Each message object should have the following keys: - **from** (string) - Required - Sender's email address. - **to** (string) - Required - Recipient's email address. - **subject** (string) - Required - Subject of the email. - **content** (string) - Required - Body of the email. ### Request Example ```json { "key":"your_api_key", "messages": [ { "from":"me@domain.com", "to":"him@domain.com", "subject":"Just testing", "content":"This is just an email to test Emailqueue" }, { "from":"me@domain.com", "to":"him@domain.com", "subject":"Testing again", "content":"This is another test" } ] } ``` ### Response #### Success Response (200) - **result** (boolean) - True if all emails were injected successfully, false otherwise. - **errorDescription** (string) - A description of the error, if any. #### Response Example ```json { "result": true, "errorDescription": null } ``` ``` -------------------------------- ### Send Multiple Emails via API (PHP) Source: https://context7.com/tin-cat/emailqueue/llms.txt Use this function to send an array of email messages in a single API request. Ensure the endpoint and API key are correctly configured. ```php $apiKey, "messages" => $messages ]); curl_setopt($curl, CURLOPT_URL, $endpoint); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, ["q" => $payload]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($httpCode !== 200 || $response === false) { throw new RuntimeException("API request failed (HTTP $httpCode)"); } return json_decode($response, true); } $result = emailqueueApiCall( "https://emailqueue.example.com/api/", "your-secret-api-key-here", [ [ "from" => "noreply@example.com", "to" => "alice@example.com", "subject" => "Newsletter - June Edition", "content" => "

Hello Alice!

", "priority" => 10 ], [ "from" => "noreply@example.com", "to" => "bob@example.com", "subject" => "Newsletter - June Edition", "content" => "

Hello Bob!

", "priority" => 10 ] ] ); // Expected: ["result" => true, "description" => false] if ($result["result"]) { echo "All messages queued.\n"; } else { echo "Error: " . $result["description"] . "\n"; } ?> ``` -------------------------------- ### Wipe Entire Queue - PHP Source: https://context7.com/tin-cat/emailqueue/llms.txt Deletes every email record from the database, including both sent history and pending queue entries. This action permanently deletes all emails. ```php empty_all()) { echo "All email records wiped.\n"; } else { echo "Failed to wipe email records.\n"; } ``` -------------------------------- ### Discard Pending Queue - PHP Source: https://context7.com/tin-cat/emailqueue/llms.txt Deletes all unsent emails from the queue. Use with caution as this causes permanent loss of any email that had not yet been delivered. ```php empty_queued()) { echo "Pending queue cleared.\n"; } else { echo "Failed to clear queued emails.\n"; } ``` -------------------------------- ### Pause and Unpause Email Delivery - Bash Source: https://context7.com/tin-cat/emailqueue/llms.txt Shell scripts to pause or resume email delivery processing by setting or clearing a flag file. When paused, cron-triggered delivery runs exit immediately. ```bash # Pause delivery (e.g., before maintenance or SMTP reconfiguration) /var/www/emailqueue/scripts/pause # Output: Emailqueue paused. # Check status in frontend or simply try a delivery run: /var/www/emailqueue/scripts/delivery # Output: 15/6/2024 10:30.00 Emailqueue:Delivery [Paused / Not sending] # Resume delivery /var/www/emailqueue/scripts/unpause # Output: Emailqueue unpaused. ``` -------------------------------- ### Direct Database Injection - SQL Source: https://context7.com/tin-cat/emailqueue/llms.txt Inserts emails directly into the 'emails' table using SQL. This method is suitable for non-PHP applications or batch imports via SQL tooling. ```sql INSERT INTO emails ( priority, is_immediate, is_sent, is_cancelled, is_blocked, is_sendingnow, send_count, error_count, date_injected, date_queued, is_html, `from`, from_name, `to`, subject, content, list_unsubscribe_url ) VALUES ( 10, -- priority (lower = higher priority) 1, -- is_immediate 0, -- is_sent 0, -- is_cancelled 0, -- is_blocked 0, -- is_sendingnow 0, -- send_count 0, -- error_count NOW(), -- date_injected NULL, -- date_queued (NULL = send ASAP) 1, -- is_html 'noreply@example.com', -- from 'My App', -- from_name 'user@example.com', -- to 'Direct SQL injection test', -- subject '

Hello from SQL!

', -- content 'https://example.com/unsub' -- list_unsubscribe_url ); ``` -------------------------------- ### Clear Sent Email History - PHP Source: https://context7.com/tin-cat/emailqueue/llms.txt Deletes all emails from the database that have already been delivered. This is useful for reclaiming database space without losing pending messages. ```php empty_delivered()) { echo "Delivered email history cleared.\n"; } else { echo "Failed to clear delivered emails.\n"; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.