Support

Account

Home Forums General Issues Need some email form logic help

Helping

Need some email form logic help

  • I have a form that gets emailed to the user when the form is submitted (see below). As a part of that email I send the user a link to their post that they can access later if needed.

    My problem is, when users access their post from the link I send them, the wp_mail function executes a second time. In fact, it executes every time they access the post link.

    Right now I’m checking if the email contains an email address to send the email. I’ve also tried evaluating the status of the post, only sending the email if the post status is not ‘publish’.

    $postStatus = get_post_status( $pov_id )
    if ($postStatus != 'publish') {
        email the form
    }
    

    Obviously, once the post is submitted it’s always published so this doesn’t work either.

    I have tried putting the email code in the functions.php and in the form template itself and I get the same results.

    Any idea what I can put in the If statement that will evaluate $true only once, when the post is first submitted?

    if ($email) {
    			
    			$subject = "POV Travel Calculator Summary";
    			
    			/* Let's prepare the message for the e-mail */
    			$message = "Hello!
    
    			Your estimated PCS Travel Pay summary is below.
    
    			DISLOCATION ALLOWANCE
    			DLA rate: $".$dla."
    
    			AUTHORIZED TRAVEL TIME
    			" .$totalDays." days
    
    			FLAT PER DIEM
    			Total Flat Per Diem: $".$totalPerdiem."
    
    			MALT (Monetary Allowance in Lieu of Transportation)
    			Total mileage for ".$povs." POVs: $".$rPOVcalc."
    
    			Total Travel Entitlement: $".$totalTvl."
    			
    			Thanks for visiting PCSCalculator.com and good luck with your PCS.
    
    			David Hall
    			";
    			
    			//sends email
    			wp_mail($email, $subject,$message,'From: pcs@pcscalculator.com','-f pcs@pcscalculator.com');
    	}
  • Hi @signalwarrant

    Please check the ‘Contact form’ example in this link: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/#related.

    I hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.