wordpresscustom-post-typeauto-responder

Custom post type to work with html auto reply


I'm trying to setup a custom post type for Landing Pages in WordPress, including the option to customize the text for the html auto response email.

I am able to call the post meta on a different page using using the following loop, but I can't figure out how to put it in a format that works in the html auto response.

Is it possible to turn the following loop into this ". $_POST['content'] ." or something more appropriate?

<?php
$args = array( 'post_type' => 'landing_pages');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo esc_html( get_post_meta( get_the_ID(), 'landing_pages_short_description', true ) );
endwhile;
wp_reset_query();
?>

Here is the html auto response

<?php

if(!empty($_POST['rev_captcha'])) {
    die('Nice try robot. Nothing for you here.');
}

$autoResponse = true;
$autoResponseSubject = "Brand Name: A copy of your message";
$autoResponseMessage = "<html>
<head>
    <title>Brand Name: A copy of your message</title>
</head>
<body>
<table cellpadding='0' cellspacing='0' width='100%' border='0' bgcolor='#f0f3f5' style='margin:0;padding:0;padding-bottom:15px;width:100%!important;height:100%!important;line-height:100%!important;background:#f0f3f5'>
<tbody>
    <tr>
        <td width='100%' height='110px' valign='top'>
            <table cellpadding='0' cellspacing='0' width='95%' border='0' align='center'>
                <tbody>
                <tr>
                    <td width='40%' align='center' style='padding:25px 0 0'>
                        <img src='' width='160' height='55' alt=''>
                    </td>
                    <td width='60%' style='padding:40px 0 0'>
                    </td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <tr>
        <td width='100%' valign='top' align='center'>
            <table cellpadding='0' cellspacing='0' border='0' align='center' width='95%' bgcolor='#ffffff' style='background:#ffffff;padding-top:0px;border:1px solid #eeeeee;border-top:none' valign='top'>
                <tbody>
                <tr>
                    <td align='center' style='padding-bottom:30px;padding-top:50px;border-bottom:1px solid #eeeeee'>
                        <p style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;color:#444444;margin:0 30px 5px;padding-top:10px;line-height:1.5\">
                        <strong style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:32px;line-height:30px;color:#444444\">Good news, ". $_POST['name'] ."!</strong></p>
                            <p style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;color:#444444;margin:0;padding: 10px 50px 30px;line-height:1.5;text-align:center\">Your message has been sent.</p>
                        <p style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;color:#444444;margin:0;padding: 10px 50px 0;line-height:1.5;text-align:left\">Here is a copy for your records:</p>
                        <p style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;color:#444444;margin:10px 0 10px 52px;padding:0 50px 0 20px;border-left:4px solid #666666;line-height:1.5;text-align:left\"><em>". $_POST['notes'] ."<br>--<br>". $_POST['name'] ."<br>". $_POST['phone'] ."<br>". $_POST['email'] ."</em></p>
                        <br>
                        <p style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;color:#444444;margin:0;padding: 10px 50px 0;line-height:1.5;text-align:left\">Sent from: ". $_POST['referrer'] ."</p>
                    </td>
                </tr>
                <tr>
                    <td align='center'>
                        <p style=\"font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;color:#888888;line-height:1.3;padding:10px 50px\">Thanks for contacting</p>
                    </td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
</tbody>
</table>
";

$autoResponseHeaders  = "From: ___@___.ca"."\r\n";
$autoResponseHeaders .= "MIME-Version: 1.0"."\r\n";
$autoResponseHeaders .= "Content-type: text/html; charset=iso-8859-1"."\r\n";

$email_to =   $_POST['email'];
$name     =   $_POST['name'];
$phone     =   $_POST['phone'];
$notes  =   $_POST['notes'];
$referrer  =   $_POST['referrer'];

$time = date('F j, Y g:i:s A T', time());
$message = "From: $name "."\r\n"."Email: $email_to "."\r\n"."Time: $time "."\r\n";
$headers  = "From: $email_to"."\r\n";
$headers .= "Reply-To: $email_to"."\r\n";

if(mail('___@___.ca', 'Brand Name', $notes . "\r\n \r\n" . $name . "\r\n". $phone . "\r\n". $email_to . "\r\n \r\n" . 'Sent from: ' . $referrer , $headers)){
    if($autoResponse === true){
        mail($email_to, $autoResponseSubject, $autoResponseMessage, $autoResponseHeaders);
    }
    header("Location:/sent.php" ); // send to the proper page when done.
}else{
    echo 'failed';// ... or this one to tell it that it wasn't sent
}
?>

Solution

  • on the file single-landing_page.php create a hidden form field

          <input type="hidden" name="custom_postmeta" value="<?php echo esc_html( get_post_meta( get_the_ID(), 'landing_pages_short_description', true ) ); ?>" />
    

    then on the other file as you get all other fields you can get this hidden field too like

           $custompostmeta =   $_POST['custom_postmeta'];
    

    then concatinate this $custompostmeta variable within your html table Hope it will work