# How to trigger email for manually added lead

**URL:** https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012
**Category:** Product Support
**Created:** [December 18, 2015, 9:18am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012 "2015-12-18T09:18:00Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 18, 2015, 9:18am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/1 "2015-12-18T09:18:00Z")

</div>

These are my steps :

1. I added ‘leadname’ as a new lead.  
2. I created welcome email.  
3. Then I built my campaign ‘Test Campaign’ complete with campaign builder. I set the action timing of the welcome email by ‘When Triggered’.  
4. I edited ‘leadname’, and activate ‘Campaign leadname is part of’ : Test Campaign.  
  
  
  
The question is, how do I trigger the welcome email to send to leadname ? Is there something I missed ?  
  
Thanks

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 18, 2015, 9:18am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/2 "2015-12-18T09:18:00Z")

</div>

These are my steps :

1. I added ‘leadname’ as a new lead.
2. I created welcome email.
3. Then I built my campaign ‘Test Campaign’ complete with campaign builder. I set the action timing of the welcome email by ‘When Triggered’.
4. I edited ‘leadname’, and activate ‘Campaign leadname is part of’ : Test Campaign.

The question is, how do I trigger the welcome email to send to leadname ? Is there something I missed ?  
Thanks

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 18, 2015, 9:47am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/3 "2015-12-18T09:47:02Z")

</div>

Do you have the crons configured correctly? [https://www.mautic.org/getting-started/](https://www.mautic.org/getting-started/)

The campaign should start for the lead when you add him/her to the campaign. Doesn’t matter how he/she was added.

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 20, 2015, 2:00am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/4 "2015-12-20T02:00:57Z")

</div>

Thank you for your response.

Once I updated the cron, the wecome email is sent.  
However, if I repeat another manual lead add and set its campaign, mautic did not send welcome email. Do I need to update the cron all the time ?

Please advise, thank you.

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 20, 2015, 10:14am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/5 "2015-12-20T10:14:13Z")

</div>

Ehm, I’m not sure what you mean. [Cron](https://en.wikipedia.org/wiki/Cron) runs the commands every X minutes. You maybe only executed the command manually?

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 20, 2015, 10:26pm UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/6 "2015-12-20T22:26:24Z")

</div>

I have set the cron job using ‘crontab -e’ command.

This is my ‘crontab -l’ result

```auto
* * * * * php apps/mautic/public/app/console mautic:leadlists:update --env=prod
* * * * * php apps/mautic/public/app/console mautic:campaigns:update --env=prod
* * * * * php apps/mautic/public/app/console mautic:campaigns:trigger --env=prod
* * * * * php apps/mautic/public/app/console mautic:email:process --env=prod
```

The welcome email was not triggered automatically everytime I add new lead.

However, if I run the cron command manually from SSH, the welcome email was sent

```auto
~$ php apps/mautic/public/app/console mautic:campaigns:trigger --env=prod
Triggering events for campaign 1
Triggering first level events
1 total events(s) to be processed in batches of 100
 1/1 [============================] 100%
1 event(s) executed

Triggering scheduled events
0 total events(s) to be processed in batches of 100
0 event(s) executed

Triggering 'non-action' events
7 total lead(s) to be analyzed in batches of 100
 14/14 [============================] 100%
0 event(s) executed

```

Thank you for your help.

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 20, 2015, 10:36pm UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/7 "2015-12-20T22:36:12Z")

</div>

Then your cron is not configured properly. Check the path to Mautic. That is the most common mistake. If you cannot make it work, contact the provider of your server and ask him for help with cron configuration.

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 21, 2015, 2:35am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/8 "2015-12-21T02:35:40Z")

</div>

It turned out my VPS ( Ubuntu with ServerPilot ) uses [multiple PHP versions](https://serverpilot.io/community/articles/how-to-use-the-php-cli.html)

This is from [ServerPilot documentation](https://serverpilot.io/community/articles/how-to-use-cron-to-schedule-scripts.html) concerning Cron Jobs :

> [@](#):
>
> The best way to run PHP scripts through cron is using web requests to the full URL of the script on your website. This can be done using the wget command, as shown in the examples above.
> 
> Although it is possible to use the PHP CLI to run scripts, your scripts will not have the same environment settings when run through the PHP CLI. As a result, they may not work correctly.

```auto
# Good: works as if requested through your browser.
@hourly wget -q -O - "http://example.com/cron.php"

# Bad: may not work at all or may have errors.
@hourly php5.6-sp /srv/users/serverpilot/apps/APPNAME/public/cron.php
```

When I run this command directly into SSH `
php5.6-sp /srv/users/serverpilot/apps/mautic/public/app/console mautic:campaigns:trigger --env=prod
`

Sometimes it runs well, but sometimes it throws errors : Script in progress. Use -f or --force to force execution

Does Mautic has cron php file that allows me to run the cron using `wget -q -O - "http://example.com/cron.php`?

Thank you very much.

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 21, 2015, 8:04am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/9 "2015-12-21T08:04:04Z")

</div>

Take a look at [https://gist.github.com/escopecz/9a1a0b10861941a457f4](https://gist.github.com/escopecz/9a1a0b10861941a457f4)

If you see the “May the force be with you” 😉 message, it can mean 2 things:

1. The previously triggered script is still running. (As it say “Script in progress”)
2. Or an error occurred during the previously executed command. You should see such error in the logs.

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 21, 2015, 8:27am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/10 "2015-12-21T08:27:56Z")

</div>

Thank you for the response, we’re getting close…

Upon clicking on the campaign trigger link, I got this:

```auto
[RuntimeException]                                                                                                                         
  Failed to start the session because headers have already been sent by "/srv/users/serverpilot/apps/mautic/public/command.php" at line 51.  
```

Do you have any idea ?

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 21, 2015, 8:29am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/11 "2015-12-21T08:29:31Z")

</div>

Yes, read the comments below the script. I’ll probably remove the line 51 since it causes troubles sometimes.

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 21, 2015, 8:38am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/12 "2015-12-21T08:38:40Z")

</div>

I’m not sure which line to be commented out since commenting out line #51 does not seem fix the issue. any clue ?

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 21, 2015, 8:47am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/13 "2015-12-21T08:47:03Z")

</div>

Tell me what does it say when you comment out the line 51. I cannot reproduce it in any of my environments.

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 21, 2015, 9:55am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/14 "2015-12-21T09:55:30Z")

</div>

I did hard refresh, and it seems to be working in the browser.

However, implementing this in the SSH

```auto
wget -q -O "http://mautic.djavaweb.xyz/command.php?mautic&task=mautic%3Acampaigns%3Atrigger"
```

Resulting : wget: missing URL

Do you know how to properly execute PHP script from SSH ?

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 22, 2015, 1:40am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/15 "2015-12-22T01:40:15Z")

</div>

I was able to execute the PHP via crontab, I missed the ‘-’ character right before the URL.

However, I got another issue similar to console execution error that I had posted before.  
Executing the following command :

```auto
$ wget -q -O - "http://mautic.djavaweb.xyz/command.php?mautic&task=mautic:campaigns:trigger"
```

The response was :

```auto
<pre>
Script in progress. Use -f or --force to force execution.
</pre>
```

When I run the command.php via browser `http://mydomain.com/command.php?mautic&task=mautic:campaigns:trigger`

I got same error message : `Script in progress. Use -f or --force to force execution.`

---

<div class="post-metadata">

### Author: ![yoneth](https://avatars.discourse-cdn.com/v4/letter/y/71c47a/32.png) [@yoneth](https://forum.mautic.org/u/yoneth)
#### Post date: [December 22, 2015, 5:07am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/16 "2015-12-22T05:07:29Z")

</div>

Well… I reverted back to console execution in crontab.  
But this time I add `-f` to force execution. It looks like it’s working just fine up to now.

Is there any side effect for Mautic system if I choose the script to be forced executed ?

---

<div class="post-metadata">

### Author: ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)
#### Post date: [December 23, 2015, 8:37am UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/17 "2015-12-23T08:37:30Z")

</div>

I described what the force is needed for above. Or should I describe it in another words?

---

<div class="post-metadata">

### Author: ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)
#### Post date: [February 2, 2020, 10:56pm UTC](https://forum.mautic.org/t/how-to-trigger-email-for-manually-added-lead/3012/18 "2020-02-02T22:56:20Z")

</div>


