# laravel-ai-email-assistant - github.com

laravel-ai-email-assistant - github.com

Description  
This package can generate an email from a prompt with the OpenAI GPT API.

It provides a Laravel service class that can build a prompt to request the generation of email messages.

The package can call the OpenAI GPT API to request the generation of a personalized email message based on the prompt request text.

It can:

\- Use predefined tone and style options  
\- Use custom prompts and message templates

Instructions  
Install the package using Composer.  
Configure your OpenAI API key in .env.  
Use the included AIEmailService service to generate or draft emails dynamically.  
Integrate it into your controller or automation workflows.  
Details  
? Laravel AI Email Assistant (by OmDiaries)  
AI-powered Email Assistant for Laravel 9, 10, and 11 ? automatically generate personalized, well-structured emails (welcome, follow-up, sales pitch, and more) using OpenAI or other AI models. Built with ?? by Om Diaries.

?? Badges  
License: MIT Laravel PHP AI Powered

? Table of Contents  
Installation  
Configuration  
Mock Mode (No API Key)  
Usage Example  
Output Example  
Testing  
Contributing  
License  
?? Installation  
composer require omdiaries/laravel-ai-email-assistant  
? Configuration  
If not auto-published, manually publish the config file:

php artisan vendor:publish --tag=ai-email-config  
Add your OpenAI API key in the .env file:

OPENAI\_API\_KEY=your\_api\_key\_here  
You can also modify the default configuration in:

config/ai-email.php  
? Mock Mode (No API Key)  
If you don?t have an API key or just want to test locally, Mock Mode lets you simulate AI responses.

The package automatically switches to mock mode when: - OPENAI\_API\_KEY is missing, invalid, or - your API quota is exceeded.

When this happens, a sample AI-generated email will be returned (instead of calling the real API). Perfect for local development or CI/CD testing.

Example .env setup:

\# Without real API key (enables Mock Mode)  
OPENAI\_API\_KEY=  
AI\_EMAIL\_MOCK=true  
You?ll see a default output like:

Subject: Welcome to OM Diaries  
Body: Hello Mike, welcome aboard! This is a sample AI email generated in mock mode.  
? Usage Example  
use AIEmail;

$email = AIEmail::generate('welcome', \[  
 'customer\_name' =&gt; 'Mike',  
 'product' =&gt; 'Pro Plan',  
 'company\_name' =&gt; 'OM Diaries'  
\], \['tone' =&gt; 'friendly'\]);  
? Output Example  
Hi Mike,

Welcome to OM Diaries! We're thrilled to have you on our Pro Plan.   
Get ready for smarter communication powered by AI.

Cheers,   
The OM Diaries Team  
? Testing  
You can test it quickly via a route in web.php:

Route::get('/test-ai-email', function () {  
 $email = AIEmail::generate('welcome', \[  
 'customer\_name' =&gt; 'Mike',  
 'product' =&gt; 'Pro Plan',  
 'company\_name' =&gt; 'OM Diaries'  
 \]);  
 return nl2br($email);  
});  
Then visit:

http://yourapp.test/test-ai-email  
? Contributing  
Contributions are welcome! If you?d like to improve this package, feel free to fork the repo and create a pull request.

? License  
This project is open-sourced under the MIT License.