:
/ 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屋!