0

我想在我的电子邮件中显示推荐链接。这是我到目前为止得到的。

<form method="POST" action="javascript:" name="form">
            <br /><label> <input type="text" name="text" id="text" placeholder="Name" value="" /> </label>
            <br /><label> <input type="text" name="email" id="email" placeholder="Email" value="" /> </label>
            <br /><label> <input type="text" name="phone" id="phone" placeholder="Phone" value="" /> </label>
            <br /><label> <input type="text" name="company" id="company" placeholder="Company" value="" /> </label> 
            <br /><label> <textarea name="textarea" id="textarea" placeholder="Message" rows="3" value="0" /></textarea> </label>
            <br /><label> <input type="text" name="referrer" id="WelcomePlaceHolder" placeholder="Referrer" value="" style="display: none;"/></textarea> </label>
        <br />
            <br /><label> <input class="homebotton" type="button" name="button" id="button" placeholder="button" value="Send" /> </label>
         </form>

表格发送到电子邮件:

$message .= '<tr><td>Name : </td><td>' . $_REQUEST['text'] . '</td><tr>';
    $message .= '<tr><td>Email : </td><td>' . $_REQUEST['email'] . '</td></tr>';
    $message .= '<tr><td>Phone : </td><td>' . $_REQUEST['phone'] . '</td></tr>';
    $message .= '<tr><td>Company : </td><td>' . $_REQUEST['company'] . '</td></tr>';
    $message .= '<tr><td>Message : </td><td>' . $_REQUEST['textarea'] . '</td></tr>';
    $message .= '<tr><td>Referral Site : </td><td>' . $_REQUEST['referrer'] . '</td></tr>'; 

用于检索推荐人链接的 Javascript。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//Add urls regular expressions and your message(any HTML Code) to the array
var msgs = [
//null url : to show a message for direct traffic (no referer, some one who remember your site url!)
{'url':null,                           'msg':'I am glad you remember my site URL, enjoy your stay'}
//My url! : show message for referrals from your own site or null so you do not annoy them
,{'url':/^http:\/\/(\w+\.)?moretechtips\.net/,    'msg':null}
//Other urls
,{'url':/^http:\/\/(\w+\.)?google\.com/,      'msg':'Welcome googler, Hope you will find what you looking for'}
,{'url':/^http:\/\/(\w+\.)?dzone\.com/,         'msg':'Welcome fellow dzone reader, if you like it please vote it up'}
,{'url':/^http:\/\/(\w+\.)?digg\.com/,         'msg':'Welcome digger, if you like it please digg it'}
,{'url':/^http:\/\/(\w+\.)?propeller\.com/,      'msg':'Welcome propeller user, hope you will like it here'}
//generic pattern: to show generic message for referrers that you did not specify one for
//You must keep it at the end of the list as it will match any non empty referrer
,{'url':/^http:\/\//,               'msg':'Hello their.. Hope you will find what you looking for'}
];
function DetectReferrer(){
   var div = $('#WelcomePlaceHolder');
   //if Div was not placed means , not to show message
   if (!div.length) return;
   var ref = document.referrer.toLowerCase();
   var msg = findMatch(ref);
   // if not null msg found
   if(msg) {
      //Add Close Button and Show up message
      div.html( '<a href="javascript:void(0)" class="CloseButton">X</a>' + msg).show('slow',function(){
         //Hide On click close Button
         $('.CloseButton',div).click(function(){ div.hide() })
      });
   }
}
function findMatch(ref) {
   for(var i=0; i<msgs.length; i++)
      if( ( ref=='' && msgs[i].url==null) || (ref>'' && ref.match(msgs[i].url) ) )
         return msgs[i].msg;
   return null;
}

// Call the Referrer Detector function on document ready
$(DetectReferrer);
</script>

该脚本有效。我试图显示发送到我的电子邮件的推荐链接,但它是空的。推荐链接为空。我希望我说得通。

4

1 回答 1

0

这将从msgs电子邮件中的表格发送消息。

if(msg) {
   //Add Close Button and Show up message
   div.html( '<a href="javascript:void(0)" class="CloseButton">X</a>' + msg).show('slow',function(){
      //Hide On click close Button
      $('.CloseButton',div).click(function(){ div.hide() })
   });
   // Include message in form data
   div.val(msg);
}

如果您只想要引用 URL,无论它是否在表中,只需执行以下操作:

div.val(ref);

之前if (msg)

要将其发送到 PHP 脚本,您需要将表单字段更改为:

<input type="hidden" name="referrer" id="WelcomePlaceHolder" placeholder="Referrer" value=""/>

display: none没有发送到服务器的表单字段,这就是type="hidden"它的用途。

于 2013-01-17T01:52:18.450 回答