Jump to content

bold font in php email


Go to solution Solved by ginerjm,

Recommended Posts

Hi

 

Sorry I have tried all different ways to get part of the following line of code in bold

$message .= "Repair Job ID: " . mysqli_insert_id($mysqli) . " (Enter this ID number into link below)" . "\n\n";

I want the (Enter this ID number into link below) to be in bold but when I added <strong> just before it, it outputted the html tag so made the line like the following but didn't work as just outputs the html tag as well as am guessing it is because I have wrapped it in " " but then would be wrong if I took the " " out, is that right?

$message .= "Repair Job ID: " . mysqli_insert_id($mysqli) . "<strong>" . " (Enter this ID number into link below)" . "</strong> . "\n\n";

Sorry, I have tried myself first before posting and have looked all over for the solution and tried different ways

 

Link to comment
https://forums.phpfreaks.com/topic/299508-bold-font-in-php-email/
Share on other sites

Use like you expect. However your emails have to be sent as HTML, which basically means formatting everything in the email as if it were HTML. Preferably with and and

s and such.

Once you have the HTML markup correct (you can send yourself test emails to verify that), make whatever you use to send emails send them as HTML. If you're not sure about how to do that, we'll need to see the code that does the actual sending.

Sorry got bit lost, below is the whole coding that does the php email

header('Content-Type: text/html;charset=utf-8');
$header = "From: enquiries@it-doneright.co.uk\n"
. "Reply-To: enquiries@it-doneright.co.uk\n";
$subject = "Booked Repair Information";
$email_to = "$customer_email";
$message .= "Below is your repair details to track the repair status\n\n";
$message .= "Your Name: $customer_name\n";
$message .= "Your Email: $customer_email\n";
$message .= "Your Phone Number: $customer_phone\n";
$message .= "PC/Laptop Make: $computer_make\n";
$message .= "PC/Laptop Model: $computer_model\n";
$message .= "Assigned to Technician: $technician\n";
$message .= "Current Repair Status: $status\n";
$message .= "Expected Start Date: " . date("d/m/Y", strtotime($exstdate)) . "\n";
$message .= "Expected Start Time: $exstime\n";
$message .= "Expected Repair Date: " . date("d/m/Y", strtotime($exrdate)) . "\n";
$message .= "Expected Repair Time: $exrtime\n";
$message .= "Dropoff or Pickup: $deltype\n";
$message .= "Comments: $comments\n";
$message .= "Repair Cost: " . "\243" . $cost . "\n\n";
$message .= "Repair Job ID: " . mysqli_insert_id($mysqli) . " (Enter this ID number into link below)" . "\n\n";
$message .= "http://www.it-doneright.co.uk/track-my-repair.php";
mail($email_to, $subject ,$message ,$header ) ;

I am testing it and having them sent to myself

Where are you setting the email for html content???  You are sending a header to the client, but that's not going to affect the email is it?  You're not sending the email to the client - you are sending it to an email address.

 

Google something like "send html mail" for examples.

Hi

 

I have finally got the HTML email all working ok but got stuck on a few lines which I have added below, I can't work out how to output the date format to dd/mm/yyyy and also output the last id number inserted

<p>Expected Start Date: date('d/m/Y', strtotime($exstdate))</p>
<p>Expected Repair Date: date('d/m/Y', strtotime($exrdate))</p>
<p>Repair Job ID: . mysqli_insert_id($mysqli) . <strong>(Enter this ID number into link below)</strong></p>

The whole code is below

$to = "$customer_email";
$subject = "Booked Repair Information";

$message = "
<html>
Hello <strong>$customer_name</strong>

<h2>Below is your repair details to track the repair status</h2>

<p>Your Name: $customer_name</p>
<p>Your Email: $customer_email</p>
<p>Your Phone Number: $customer_phone</p>
<p>PC/Laptop Make: $computer_make</p>
<p>PC/Laptop Make: $computer_model</p>
<p>Assigned to Technician: $technician</p>
<p>Current Repair Status: $status</p>
<p>Expected Start Date: date('d/m/Y', strtotime($exstdate))</p>
<p>Expected Start Time: $exstime</p>
<p>Expected Repair Date: date('d/m/Y', strtotime($exrdate))</p>
<p>Expected Repair Time: $exrtime</p>
<p>Dropoff or Pickup: $deltype</p>
<p>Comments: $comments</p>
<p>Repair Cost: '\243' $exstime . </p>
<p>Repair Job ID: . mysqli_insert_id($mysqli) . <strong>(Enter this ID number into link below)</strong></p>
<p>http://www.it-doneright.co.uk/track-my-repair.php</p>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <enquiries@it-doneright.co.uk>' . "\r\n";

    mail($to,$subject,$message,$headers);

You can't include function calls inside strings as you are doing. You need to split the string in two and concatenate the function call.

 

For example, instead of

 

    $message = "<p>Expected Repair Date: date('d/m/Y', strtotime($exrdate))</p>";

 

you would need

 

    $message = "<p>Expected Repair Date: " . date('d/m/Y', strtotime($exrdate)) . "</p>";

 

 

Alternatively you could store the results of the function calls in variables and then put those in the string EG

$newId = mysqli_insert_id($mysqli);
$repairDate = date('d/m/Y', strtotime($exrdate));

$message = "<p>Expected repair date: $repairDate</p>
            <p>ID: $newId</p>";
Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.