Appointments+ email confirmation to multiple email addresses, with different contents?

Is it possible to send client confirmation emails to more than one email address, ideally containing different content?

I have an email->SMS gateway which will accept emails to phonenumber@mysmsgateway.com and convert them to SMS. I would like Appointments+ to send 2 confirmation emails to clients, one to their email address and one to client-phone-number@mysmsgateway.com (with client-phone-number being a variable populated from the PHONE field)

If possible I would like to be able to send a different email to both addresses so as to keep the SMS confirmation short.

I have seen there is a plugin which supports a couple of SMS gateways but sadly not mine, however if I can set up an additional confirmation email as outlined then this would solve my problem.

  • Michael Bissett
    • Recruit

    Hi @Michael, hope you're doing well today! :slight_smile:

    While this may take a fair amount of custom coding, I'd like to have a closer look at how you've set things up here, could you please send in the following:

    - Mark to my attention, the subject line should contain only: ATTN: Michael Bissett
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include WordPress admin access details
    - Include FTP log-in details
    - Include any relevant URLs/information for your site

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thanks a bunch! :slight_smile:

    Kind Regards,
    Michael

  • Michael Bissett
    • Recruit

    Hi @Michael, thanks for your patience here! :slight_smile:

    After some further investigation (as well as a little regex magic), here's the code you'll need for this:

    add_action( 'app_confirmation_sent', 'app_confirmation_sent_sms', 20, 3 );
    function app_confirmation_sent_sms( $body, $r, $app_id ) {
    
    	$myphone = preg_replace('/[-\s.]+/', '', $r->phone);
    
    	wp_mail(
            	'' . $myphone . '@mysmsgateway.com',
            	'enter-subject-here',
            	'enter-message-here'
    	);
    }

    The $myphone variable is designed to filter out any spaces, hyphens, or periods entered in with the phone number, and just return the phone number entered in the Phone field on the appointment form. :slight_smile:

    Hope this helps! :slight_smile:

    Kind Regards,
    Michael

    (hat tip to @Ashok for the code inspiration for this snippet)

  • Ash
    • WordPress Hacker

    Hello @Michael

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Cheers
    Ash

  • Michael
    • Site Builder, Child of Zeus

    You guys totally nailed it and I have it working, right now it will send whatever I put in the subject and body as an SMS and it strips spaces and other erroneous characters from the phone number perfectly.

    Is there anything I can add in to the code so I can insert variables like DATE_TIME into the body text like in the standard email confirmation from the plugin?

  • Ash
    • WordPress Hacker

    Hello @Michael

    You can't use DATE_TIME in the same way, but as you have $r variable available here, you can print date using $r->start property.

    Like:

    add_action( 'app_confirmation_sent', 'app_confirmation_sent_sms', 20, 3 );
    function app_confirmation_sent_sms( $body, $r, $app_id ) {
    
    	$myphone = preg_replace('/[-\s.]+/', '', $r->phone);
    
    	wp_mail(
            	'' . $myphone . '@mysmsgateway.com',
            	'enter-subject-here',
            	'The session will start at ' . $r->start
    	);
    }

    Please let us know if that works for you.

    Cheers
    Ash

  • Michael
    • Site Builder, Child of Zeus

    Thanks Ash, that works almost perfectly. I say almost because the format it uses is YYYY/MM/DD HH:MM:SS

    Is there any way to change this output? Ideally I would like HH:MM DD/MM/YY

    If not it's no big deal, it works well enough as it is. I'm just a perfectionist :wink:

    Michael

  • Ash
    • WordPress Hacker

    Hello @Michael

    Replace this

    'The session will start at ' . $r->start

    with this

    'The session will start at ' . date_i18n( get_option( 'date_format' ), strtotime( $r->start ) ) . ' ' . date_i18n( get_option( 'time_format' ), strtotime( $r->start ) )

    Please let us know if it works.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hey there.

    Thanks for posting in this thread, however it might be best if you open your own, even if the issues seem closely related. That way it will remain independent of this one and ensure it doesn't confuse issues here if this thread needs reopening again by the author.

    It also means the member who started this thread or anyone following it isn't inundated with post notifications each time we respond to each other. A lengthy thread could annoy the original poster.

    This also allows us to better track and answer your questions to ensure we don't miss any for you.

    You can start a new thread here:

    https://premium.wpmudev.org/forums/#question

    Thanks
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.