Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

html - Need to use bold tags in php

I have this form done it complete and working fine when the form is submitted the information is emailed to an email id but all the content is shown in plain text when it delivers I want that when the form information reaches the email id it it should the field names in bold.

<?php 
$errors = '';
$myemail = 'abc@email.com';//<-----Put Your email address here.


if(
empty ($_POST['fullname']) ||
empty ($_POST['martialstatus']) ||
empty ($_POST['dateofbirth']) ||
empty ($_POST['email']) ||
empty ($_POST['telephone']) ||
empty ($_POST['cell']) ||
empty ($_POST['graduation']) ||
empty ($_POST['yearatt']) ||
empty ($_POST['department']) ||
empty ($_POST['program']) ||
empty ($_POST['permanentaddress']) ||
empty ($_POST['currentemp']) ||
empty ($_POST['designation']) ||
empty ($_POST['selfemp']) ||
empty ($_POST['officeemail']) ||
empty ($_POST['officetele']) ||
empty ($_POST['portfolio']) ||
empty ($_POST['membership']))

{
    $errors .= "
 Error: all fields are required";
}

$fullname = $_POST['fullname'];
$martialstatus = $_POST['martialstatus'];
$dateofbirth = $_POST['dateofbirth'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$cell = $_POST['cell'];
$graduation = $_POST['graduation'];
$yearatt = $_POST['yearatt'];
$department = $_POST['department'];
$program = $_POST['program'];
$permanentaddress = $_POST['permanentaddress'];
$currentemp = $_POST['currentemp'];
$designation = $_POST['designation'];
$selfemp = $_POST['selfemp'];
$officeemail = $_POST['officeemail'];
$officetele = $_POST['officetele'];
$portfolio = $_POST['portfolio']; 
$membership = $_POST['membership'];



if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Membership Information: $fullname";
    $email_body = "You have received a new message. ".
    " Here are the details:
  Personal Information 

 
    Name:                      $fullname 
 
    Martial Status:            $martialstatus 
 
    Date of Birth:             $dateofbirth 
 
    Email:                     $email 
 
    Telephone:                 $telephone 
 
    Cell:                      $cell 
 
    Year of Graduation:        $graduation 
 
    Years Attended:             $yearatt 

    Department:                $department 
 
    Program Attended:          $program 
 
    Permanent Address:         $permanentaddress 

 
    Career Information 

 
    Currently Employeed with:  $currentemp 
 
    Designation:               $designation 
 
    Self Employeed:            $selfemp 
 
    Office Email:              $officeemail 
 
    Office Telephone:          $officetele 
 
    Portfolio:                 $portfolio 

 
    MemberShip 

 
    Type of MemberShip:        $membership 

 "; 

    $headers = "From: $myemail
"; 
    $headers .= "Reply-To: $email";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Bold text can be done with an HTML email, set the content type header:

$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html;
";

Use the <strong> tag:

<strong>Name:</strong>                      $fullname <br />

Don't forget won't show a new line in an HTML email, you'll need to use <br />.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...