自定义 post 类型以使用 html 自动回复
Custom post type to work with html auto reply
我正在尝试为 WordPress 中的着陆页设置自定义 post 类型,包括自定义 html 自动回复电子邮件文本的选项。
我可以使用以下循环在不同的页面上调用 post 元,但我不知道如何将其置于 html 中可用的格式自动响应。
是否可以将下面的循环变成这个". $_POST['content'] ."
或更合适的东西?
<?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();
?>
这是html自动回复
<?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
}
?>
在文件上 single-landing_page.php
创建一个隐藏的表单域
<input type="hidden" name="custom_postmeta" value="<?php echo esc_html( get_post_meta( get_the_ID(), 'landing_pages_short_description', true ) ); ?>" />
然后在另一个文件上,当您获得所有其他字段时,您也可以像
一样获得这个隐藏字段
$custompostmeta = $_POST['custom_postmeta'];
然后在您的 html table 中连接此 $custompostmeta
变量
希望有用
我正在尝试为 WordPress 中的着陆页设置自定义 post 类型,包括自定义 html 自动回复电子邮件文本的选项。
我可以使用以下循环在不同的页面上调用 post 元,但我不知道如何将其置于 html 中可用的格式自动响应。
是否可以将下面的循环变成这个". $_POST['content'] ."
或更合适的东西?
<?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();
?>
这是html自动回复
<?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
}
?>
在文件上 single-landing_page.php
创建一个隐藏的表单域
<input type="hidden" name="custom_postmeta" value="<?php echo esc_html( get_post_meta( get_the_ID(), 'landing_pages_short_description', true ) ); ?>" />
然后在另一个文件上,当您获得所有其他字段时,您也可以像
一样获得这个隐藏字段 $custompostmeta = $_POST['custom_postmeta'];
然后在您的 html table 中连接此 $custompostmeta
变量
希望有用