> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/english/faq/cases/sending-an-incoming-fax-to-email.md).

# Sending an incoming fax to email

1. Add a new dialplan application (see [**Dialplan Applications**](/mikopbx/english/manual/modules/dialplan-applications.md)).

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FNrOZjBErG4lnGPyR87Uu%2FNEWDialplan.png?alt=media&amp;token=9dff900f-c127-4426-96c5-69abe9d4e74e" alt=""><figcaption><p>Creating a new dialplan application</p></figcaption></figure>

2. Assign an internal number, for example, **2200110**.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F8FqzbADOLLpwCnoPN7JN%2FSettingsForDialplan.png?alt=media&amp;token=ba1cc170-a282-43fe-a32f-6952f8b360d3" alt=""><figcaption><p>Parameters for dialplan</p></figcaption></figure>

3. Insert the following code into the "**Programme Code**" tab:

```php
<?php
require_once 'Globals.php';

use \MikoPBX\Core\Asterisk\AGI;
use MikoPBX\Core\System\Notifications;
use MikoPBX\Core\System\{MikoPBXConfig};

$agi     = new AGI();
$faxFile = "/tmp/" .$agi->get_variable("CDR(linkedid)", true).'.tiff';
$caller  = $agi->get_variable("CALLERID(num)", true);
$agi->exec("ReceiveFax", "{$faxFile},d"); 
$result  = $agi->get_variable("FAXOPT(status)", true);

if($result === 'SUCCESS' && file_exists($faxFile)){
    $notify = new Notifications();
    $notify->sendMail('your-email@gmail.com', 'Fax msg from '.$caller, 'Incoming fax <br><br>', $faxFile);
    unlink($faxFile);
}
sleep(1);
```

{% hint style="success" %}
In the code, replace '<your-email@gmail.com>' with your own email address.
{% endhint %}

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F3jlleZ42HrNEnc0TdFm8%2FprogrammeCodeForDialplan.png?alt=media&amp;token=721d9ca2-916a-4cd8-aceb-a1e44f896c66" alt=""><figcaption><p>Code for dialplan</p></figcaption></figure>

4. Go to the "**System file customization**" section.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2Fn06cIfMIqk6wJhcxD3gW%2FSystemFileCustomization.png?alt=media&amp;token=4edfbfbf-6903-46c5-b1b5-d2a62131f59e" alt=""><figcaption><p>System file customization section.</p></figcaption></figure>

5. Open the "**extensions.conf**" file for editing.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FNuELWVzuFh5rThr08jvu%2FEditExtensions.conf.png?alt=media&amp;token=567dc075-00ed-45a7-bc10-915ccc1dc97f" alt=""><figcaption><p>extensions.conf file</p></figcaption></figure>

6. Add the folowwing code to the end of file:

```php
[SIP-1687941868-incoming](+)
exten => fax,1,Goto(internal,2200100,1)
```

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FoNN8xxanXcjwyrtojwtz%2FcodeforExtenionsConf.png?alt=media&amp;token=c9c52180-ae54-4782-a809-01f295fad3e7" alt=""><figcaption></figcaption></figure>

Replace "2200100" with the number of **your** application.

In the code, replace "**SIP-1687941868**" with your provider's ID. You can find it in the provider's card in the browser's address bar.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F3XStuOpw48SpfaPoja1Q%2FProviderID.png?alt=media&amp;token=18907fb7-e20c-426f-ac7e-def2b35ae001" alt=""><figcaption><p>Provider ID</p></figcaption></figure>

7. Open the "**modules.conf**" file for editing.

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FOOR18KwpzDhecRg5Ek3s%2FmodulesConf.png?alt=media&amp;token=7cd59158-ba08-43dc-82c0-97c47e7a2c29" alt=""><figcaption><p>Modules.conf file</p></figcaption></figure>

8. Add the following code to the end of the file:

```php
load => res_fax.so
load => res_fax_spandsp.so
```

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2F5Awqjpe3Ng8xNAcKYziX%2FcodeForModulesConf.png?alt=media&amp;token=92b0745e-b76e-49ac-937b-5bd3e43ee625" alt=""><figcaption><p>Code for Modules.conf</p></figcaption></figure>

9. In the provider's card, in the **advanced settings**, in **additional parameters**, specify:

```php
[endpoint]
fax_detect=yes
fax_detect_timeout=30
```

<figure><img src="https://835495363-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsZ8acWnNlSalIHQjMFu1%2Fuploads%2FWcgSAALWTFpUzAVGy5Nt%2FextraParametersForProvider.png?alt=media&amp;token=7b149be9-95a0-448b-8b44-6f5e3af41b33" alt=""><figcaption><p>Additional parameters in Provider section</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mikopbx.com/mikopbx/english/faq/cases/sending-an-incoming-fax-to-email.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
