> 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="/files/UvzYx95g7RguJ0r7VaO5" alt=""><figcaption><p>Creating a new dialplan application</p></figcaption></figure>

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

<figure><img src="/files/uJXVv1gypBTbNef17k47" 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="/files/ybnjioQeSTk4GlPwghLG" alt=""><figcaption><p>Code for dialplan</p></figcaption></figure>

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

<figure><img src="/files/tYsBgqXvD9DV5euOc4N0" alt=""><figcaption><p>System file customization section.</p></figcaption></figure>

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

<figure><img src="/files/R61HVwQh4xX75UmmNNdE" 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="/files/bvjkIDwygqTdD72Zzfaf" 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="/files/hOYAHwA24D9VsymOgyau" alt=""><figcaption><p>Provider ID</p></figcaption></figure>

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

<figure><img src="/files/lQ5KrnWk2aIBS2cBkmBZ" 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="/files/7ZxiOl0Hr2NcM3sXrHvW" 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="/files/1QYSktpDJHOulorpIAiV" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
