Home Forums General Issues Need some email form logic help


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.
    			DLA rate: $".$dla."
    			" .$totalDays." days
    			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 and good luck with your PCS.
    			David Hall
    			//sends email
    			wp_mail($email, $subject,$message,'From: [email protected]','-f [email protected]');
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Need some email form logic help’ is closed to new replies.