2

我一直在寻找此功能,是否可以在用户单击mailto 时添加电子邮件客户端选择器:例如,我正在为电子邮件使用以下代码

<a href="mailto:email@me.com">Email Us</a>

如果用户想要使用 gmail/yahoo/hotmail 而不是他的默认电子邮件客户端,例如 Outlook,该怎么办。我也发现了一个类似的问题。但我需要知道这在任何情况下是否都可以使用任何 jQuery 插件或 HTML,无论它可能是什么。

4

1 回答 1

3

你不能用'mailto'功能做到这一点。但是您可以借助 php 功能实现定位电子邮件客户端。这是针对特定基于 Web 的客户端的 php 函数:

    Targeting Specific Web-based Clients

function wcs_mailto_ex($mailto='', $subject='', $body='', $client='', $link_text='', $link_title='', $at_replace='&#64;')
{
// init
$subject = rawurlencode(strip_tags($subject));
$body = str_replace('\r\n', '%0A', $body);
$body = str_replace('\n', '%0A', $body);
if (!$link_text) {$link_text = $mailto;}
$link_text = str_replace('@', $at_replace, $link_text);
$client = strtolower($client);

// default parameters (system mail: Outlook, Thunderbird, etc.)
$email['url'] = 'mailto:' . $mailto . '?subject=' . $subject . '&amp;body=' . $body;
$email['width'] = 0;
$email['height'] = 0;
$email['scrollbars'] = 0;

// constuct client-specific parameters
switch($client)
{
    case 'gmail':
    case 'g mail':
    case 'google mail':
    case 'google':
        $email['url'] = 'https://mail.google.com/mail/?view=cm&fs=1&tf=1&source=mailto&shva=1&to=' . $mailto . '&amp;su=' . $subject . '&amp;body=' . $body;
        $email['width'] = 700;
        $email['height'] = 500;
        $email['scrollbars'] = 1;
        break;
    case 'hotmail':
    case 'hmail':
    case 'livemail':
    case 'live mail':
        $email['url'] = 'http://mail.live.com/?rru=compose&amp;to=' . $mailto . '&amp;subject=' . $subject . '&amp;body=' . $body;
        $email['width'] = 850;
        $email['height'] = 550;
        $email['scrollbars'] = 1;
        break;
    case 'yahoo mail':
    case 'ymail':
    case 'yahoo':
        $body = str_replace('%0A', '<br>', $body);
        $body = urlencode(urlencode($body));
        $email['url'] = 'http://compose.mail.yahoo.com?to=' . $mailto . '&subject=' . rawurlencode($subject) . '&amp;body=' . $body;
        $email['width'] = 750;
        $email['height'] = 625;
        $email['scrollbars'] = 1;
        break;
}

// prep for popup
$wdw_name = 'wcs_mailto_ex_wdw';
$wdw_features = "scrollbars=$scrollbars,status=0,toolbar=0,location=0,directories=0,menubar=0,resizable=1,width=";
$url = $email['url'];
$width = $email['width'];
$height = $email['height'];
$scrollbars = $email['scrollbars'];

// determine if display should be a popup window
if ($email['width'])
{
    $javascript = "window.open('$url', '$wdw_name', '$wdw_features$width,height=$height');return false;";
    $output = "<a rel='nofollow' style='cursor:pointer;' onclick=\"$javascript\" title='$title'>" . $link_text . "</a>";
}
else
{
    $output = '<a href="' . $url . '" rel="nofollow" title="' . $link_title . '">' . $link_text . '</a>';
}

// exit
echo $output;
}

要定位 gmail 客户端,请按如下方式调用上述函数:

    wcs_mailto_ex('AnEmailAccount@gmail.com',
            'Test Subject Line',
            'This is a sample\n\nemail for testing.\n\nBest regards,\nme',
            'gmail',
            'gMail Client'
            );

来源:http ://wpcodesnippets.info/blog/how-to-target-mailto-email-clients.html

于 2012-10-29T05:04:32.233 回答