以下是代码:
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n Email: $email_address \n Message \n $message";
我想将粗体文字添加到:“名称:”,“电子邮件:”和“消息”
我尝试使用“< b>名称:< / b>” (当然没有空间),但它不起作用。我希望收到邮件时文本是粗体。
答案 0 :(得分:2)
//要发送HTML邮件,必须设置Content-type标头
$ headers ='MIME-Version:1.0'。为 “\ r \ n” 个;
$ headers。='Content-type:text / html; charset = iso-8859-1'。为 “\ r \ n” 个;
$email_body = "You have received a new message. ".
" Here are the details:\n\n <strong>Name:</strong> $name \n <strong>Email:</strong> $email_address \n Message \n $message";
// Mail it
mail($to, $subject, $message, $headers);
答案 1 :(得分:0)
您需要像这样设置标题内容类型: $ headers ='MIME版本:1.0'。 “ \ r \ n”; $ headers。='内容类型:text / html; charset = iso-8859-1'。 “ \ r \ n”;
这是示例....
<?php
$to = 'recivermail@email.com';
$subject = 'Your Subject';
$from = 'sender@email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Your Title</h1>';
$message .= '<b style="color:#080;font-size:18px;">How Are You?</b>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>