douwen5681 2013-03-22 18:25
浏览 42
已采纳

“To”参数在Windows中的MailTo链接中不起作用

For some reason the "To" parameter is working on my Mac in Gmail and Outlook. But when I try the links in Windows they don't work in any browser and for any client. What gives?

Now as a little backdrop, I am building the links using some JavaScript. Below is my code. Maybe I am doing this wrong. It is just odd that this would be a problem in Windows only and not be dependent on the browser or mail client.

Code:

<div class="customsms-model-box email-modal share-modal sms-modal">
  <div class="modal-title">Send a link via SMS</div>
  <form id="email-box">
    <div class="email-info">
      Web access on phone is required to view the full list. Standard text message rates from your carrier will apply. You will be sending this SMS message through your e-mail program. We will build everything for you. You will just have to send it.
    </div>

    <div class="mobile-carrier">
      <span class="carrier-label">Mobile carrier:&nbsp;</span>
      <select name="email_to_email">
        <option value='' selected="selected">Select one</option>
        <?php print users_carrier_options(); ?>
      </select>
    </div>

    <div class="recipient-phone">
      <span class="recipients-phone">Recipient's phone:&nbsp;</span>
      <input type="text" name="phone_number" value="" /><br>
      <span class="subnote">Enter phone number including area code. Numbers only, no other characters.</span>
    </div>

    <div class="email-buttons">
      <a href="#" class="orange-link send-mail" target="_blank">Send link</a>
      <a href="#" class="simple-link cancel close">Cancel</a>
    </div>
  </form>
</div>

<div class="email_body" ref="<?php print $list->id; ?>">Follow the URL to see my items! <?php print $smsLink; ?></div>

<div class="email_subject" ref="<?php print $list->id; ?>">SOME COMPANY SUBJECT</div>

<script>
jQuery(document).ready(function($) {
  var eBody = $('#modal-content .email_body').text();
  var eSubject = $('#modal-content .email_subject').text();
  var eTo = "";
  var eFrom = "<?php print $user->mail; ?>";
  update_email();

  $('a.send-mail').click(function() {
    if (eTo == '') {
      alert("You must enter an email address!");
      return false;
    }
  });

  //Replace this with something for the SMS carrier emailTo stuff
  $(".mobile-carrier select").change(function(){
    if ($(this).val() != '') {
      update_to(true);
    }
  });

  $(".recipient-phone input").change(function(){
    if ($(this).val() != '') {
      update_to();
    }
  });

  function update_to(calledBySelect) {
    if (calledBySelect != true) {
      calledBySelect = false;
    }

    var phone = $(".recipient-phone input").val().replace(/[^\d.]/g, ""); //Get the phone number and leave only digits

    //A little validation
    if (phone.length != 10 && !calledBySelect) {
      alert('You must put in a 10 digit phone number.');
      return false;
    }

    var carrier = $('.mobile-carrier select').val();//Gotta load the carrier domain
    eTo = phone + '@' + carrier; //Build the email to address
    update_email(); //Make sure all of this gets updated
  }

  function update_email() {
    $('.email-buttons a.send-mail').attr( 'href', 'mailto:?subject=' + encodeURIComponent(eSubject) + '&body=' + encodeURIComponent(eBody) + '&to=' + encodeURIComponent(eTo) + '&from=' + encodeURIComponent(eFrom) );
  }
});
</script>
  • 写回答

1条回答 默认 最新

  • drd94483 2013-03-22 18:31
    关注

    Instead of setting the to parameter set the email at the very front:

    mailto:EMAIL_ADDRESS?Subject....

    $('.email-buttons a.send-mail').attr( 'href', 'mailto:'+encodeURIComponent(eTo)+'?subject=' + encodeURIComponent(eSubject) + '&body=' + encodeURIComponent(eBody) + '&from=' + encodeURIComponent(eFrom) );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)