Mautic Community Forums

How to trigger email for manually added lead

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

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

Do you have the crons configured correctly? 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.

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.

Ehm, I’m not sure what you mean. Cron runs the commands every X minutes. You maybe only executed the command manually?

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

This is my ‘crontab -l’ result

* * * * * 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

~$ 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.

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.

It turned out my VPS ( Ubuntu with ServerPilot ) uses multiple PHP versions

This is from ServerPilot documentation concerning Cron Jobs :

# 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.

Take a look at https://gist.github.com/escopecz/9a1a0b10861941a457f4

If you see the “May the force be with you” :wink: 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.

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

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

[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 ?

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

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

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

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

However, implementing this in the SSH

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 ?

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 :

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

The response was :

<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.

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 ?

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