PHP的邮件() - 如何把一个HTML链接在电子邮件? [英] PHP mail() - How to put an html link in an email?

查看:93
本文介绍了PHP的邮件() - 如何把一个HTML链接在电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过PHP的mail()函数发送一封电子邮件。在消息中,我设置了一个如下所示的链接:

  $ message =< a href ='。 $链接。 >中。$称号。 < / A> \\\
\\\
;

但是,当收到电子邮件时,电子邮件正文会显示html代码而不是标题超链接。我对HTML电子邮件不太了解。我怎么能达到我想要得到的结果?

解决方案

尝试添加一个标题,以便邮件客户端不会相信它是纯文本:

  $ headers。='Content-type:text / html; charset = utf-8'。 \r\\\
;

请参阅

/ p>

 <?php 
//多个收件人
$ to ='aidan@example.com'。 ','; //注意逗号
$ to。='wez@example.com';

// subject
$ subject ='八月的生日提醒';

//消息
$消息='
< html>
< head>
< title>八月份的生日提醒< / title>
< / head>
< body>
< p>以下是八月即将到来的生日!< / p>
< table>
< tr>
第Person人第th日第th th月第th th第th年第th th月th th th th th th th th th th th th th th th月th th th th th th th th th th th th th th th th th月
< / tr>
< tr>
< td> Joe< / td>< td> 3rd< / td>< td> August< / td>< td> 1970< / td>
< / tr>
< tr>
< td> Sally< / td>< td> 17th< / td>< td> August< / td>< td> 1973< / td>
< / tr>
< / table>
< / body>
< / html>
';

//要发送HTML邮件,必须将Content-type标头设置为
$ headers ='MIME-Version:1.0'。 \r\\\
;
$ headers。='Content-type:text / html; charset = iso-8859-1'。 \r\\\
;

//附加标题
$标题。='To:玛丽< mary@example.com> ;,;凯利< kelly@example.com>'。 \r\\\
;
$ headers。='发件人:生日提醒< birthday@example.com>'。 \r\\\
;
$ headers。='抄送:birthdayarchive@example.com'。 \r\\\
;
$ headers。='密送:birthdaycheck@example.com'。 \r\\\
;

//邮寄
邮件($ to,$ subject,$ message,$ headers);
?>


I'm sending an email via PHP's mail() function. In the message I set a link that looks like this:

$message = "<a href='". $link. "'>" .$title. "</a>\n\n";

However, when the email is received, the email body shows the html code instead of the title as a hyperlink. I'm not very familiar with html emails. How could I achieve what I am trying to get?

Try to add an header, so that the mail client doesn't believe it is plain text:

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

See PHP mail function manual:

Example #4 Sending HTML email:

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

这篇关于PHP的邮件() - 如何把一个HTML链接在电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆