我有大约6个子域名有“联系我们”链接,我将所有这些链接发送到使用“联系表格7”的单个表单。我将?from = site-name添加到每个链接中,以便我可以在联系表单中设置$ referFrom变量。
我唯一缺少的两件事是:(1)能够将这个referFrom变量插入到每当有人提交表单时我收到的电子邮件中;(2)能够将用户重定向回他们来自的网站(存储在$ referencedFrom中)
有什么想法吗?
这是来自includes / classes.php的一些代码,我认为这些代码可能是电子邮件插入的一部分,但它没有做太多...
function mail() {
global $referrer;
$refferedfrom = $referrer; //HERE IS MY CUSTOM CODE
$fes = $this->form_scan_shortcode();
foreach ( $fes as $fe ) {
$name = $fe['name'];
$pipes = $fe['pipes'];
if ( empty( $name ) )
continue;
$value = $_POST[$name];
if ( WPCF7_USE_PIPE && is_a( $pipes, 'WPCF7_Pipes' ) && ! $pipes->zero() ) {
if ( is_array( $value) ) {
$new_value = array();
foreach ( $value as $v ) {
$new_value[] = $pipes->do_pipe( $v );
}
$value = $new_value;
} else {
$value = $pipes->do_pipe( $value );
}
}
$this->posted_data[$name] = $value;
$this->posted_data[$refferedfrom] = $referrer; //HERE IS MY CUSTOM CODE
}
我也在想我可以在这个函数的某处插入referFrom代码......
function compose_and_send_mail( $mail_template ) {
$regex = '/\[\s*([a-zA-Z][0-9a-zA-Z:._-]*)\s*\]/';
$callback = array( &$this, 'mail_callback' );
$mail_subject = preg_replace_callback( $regex, $callback, $mail_template['subject'] );
$mail_sender = preg_replace_callback( $regex, $callback, $mail_template['sender'] );
$mail_body = preg_replace_callback( $regex, $callback, $mail_template['body'] );
$mail_recipient = preg_replace_callback( $regex, $callback, $mail_template['recipient'] );
$mail_headers = "From: $mail_sender\n";
if ( $mail_template['use_html'] )
$mail_headers .= "Content-Type: text/html\n";
$mail_additional_headers = preg_replace_callback( $regex, $callback,
$mail_template['additional_headers'] );
$mail_headers .= trim( $mail_additional_headers ) . "\n";
if ( $this->uploaded_files ) {
$for_this_mail = array();
foreach ( $this->uploaded_files as $name => $path ) {
if ( false === strpos( $mail_template['attachments'], "[${name}]" ) )
continue;
$for_this_mail[] = $path;
}
return @wp_mail( $mail_recipient, $mail_subject, $mail_body, $mail_headers,
$for_this_mail );
} else {
return @wp_mail( $mail_recipient, $mail_subject, $mail_body, $mail_headers );
}
}
答案 0 :(得分:1)
我找到了一个插件,可以很好地做到这一点,还有一点:
http://wordpress.org/plugins/contact-form-7-leads-tracking/
将在发送电子邮件时将所有信息添加到电子邮件末尾
答案 1 :(得分:0)
首先,为了获得from变量,你必须插入
$referrer = $_GET['from'];
顶部脚本中的某个位置,至少在您插入的最后一行之前。
此外,在第二个脚本中,您必须以某种方式将值添加到$ mail_body,但由于我不知道该值是如何组成的,因此我无能为力。 这个表格的代码是否可以在某处在线获取?
答案 2 :(得分:0)
插入 functions.php 或创建一个简单的插件...
<强> 1 强>
function custom_wpcf7_special_mail_tag( $output, $name ) {
if ( 'from' == $name ) {
$referredFrom = ( isset($_GET["from"]) && !empty($_GET["from"]) ) ? $_GET["from"] : '';
$output = $referredFrom;
}
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'custom_wpcf7_special_mail_tag', 10, 2 );
使用电子邮件模板中的[from]
标记。
<强> 2 强>
function add_custom_js_cf7() {
$referredFrom = ( isset($_GET["from"]) && !empty($_GET["from"]) ) ? $_GET["from"] : '';
if ( $referredFrom ) {
?>
<script type="text/javascript">
var from = "<?php echo $referredFrom; ?>";
</script>
<?php }
}
add_action( 'wpcf7_enqueue_scripts', 'add_custom_js_cf7' );
并将此行添加到表单设置中的“其他设置”:
on_sent_ok: "location = from;"
http://contactform7.com/blog/2010/03/27/redirecting-to-another-url-after-submissions/
如果你在某个地方宣布它,你也可以使用global $referredFrom;
。