BeginnerScripter
BeginnerScripter

Reputation: 15

Formatting String within Variable PHP

Is it possible to format the string within a variable within PHP script.

The following script sends an email to the user. The part shown is my entire body of the email including my signature. I want to bold or change the font size of my signature and everything I've tried didn't work.

I tried including within the string, but it just reads the code and not implementing it. Tried to look over all the web to see if there's a possibility, but all the results show echo......

<?php 
    if(isset($_POST['button_1'])){
        $to = $_POST['email'];
        $from = 'xxxxx <[email protected]>';
        $subject = "Thank you for your interest";
        $message ="Name" . "\n" . "Work" . "\n" . "Position" . 
                    "\n" . "(xxx) xxx-xxxx" . "\n" . "[email protected]";
        $headers="From:" . $from; mail($to, $subject, $message, headers);
        mail($to,$subject,$message,$headers); 
    }
?>

Trying to format "Name" within $message

Upvotes: 1

Views: 247

Answers (1)

Dmitriy Buteiko
Dmitriy Buteiko

Reputation: 644

You should use html in your text body. For example, to make text to be bold you should use:

$message = "<b>Your text here</b>";

To enable html in your message your should set these headers:

$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

Upvotes: 1

Related Questions