How to get web html form output in color and

Oh, I got it. Thanks.

1 Like

Sir, I am using PHPMailer.

class PHPMailer
{
    const CHARSET_ASCII = 'us-ascii';
    const CHARSET_ISO88591 = 'iso-8859-1';
    const CHARSET_UTF8 = 'utf-8';

    const CONTENT_TYPE_PLAINTEXT = 'text/plain';
    const CONTENT_TYPE_TEXT_CALENDAR = 'text/calendar';
    const CONTENT_TYPE_TEXT_HTML = 'text/html';
    const CONTENT_TYPE_MULTIPART_ALTERNATIVE = 'multipart/alternative';
    const CONTENT_TYPE_MULTIPART_MIXED = 'multipart/mixed';
    const CONTENT_TYPE_MULTIPART_RELATED = 'multipart/related';

Yes you would need to send email as HTML in order to use any text styles. But as droopsnoot already pointed out, where is the code that processes the form? This is where you would check user input, send the user any error messages, create the “content” of your email, and it is here where you would style the message the way you wish before calling your mail function.

I don’t see any submit button, so you are processing this form how?
How is the forum submitted?
Where is the code the receives it?
Where is the email function being called?

I assume you didn’t write this code but you need to follow the path or flow and show all related parts.

The function that you shared does not use PHPMailer, it uses the built-in PHP mail() function:

return mail($toMail, $subject, $message, $header);

It may be that you have a different section of code that uses PHPMailer, in which case you need to post it.

1 Like

OK. I will go step-by-step.
Here is abridged form:

<form id="kontaktformular" class="kontaktformular" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" accept-charset="utf-8" enctype="multipart/form-data">
              <p><FONT size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <table><tr>		<div class="row">
			<td>	<div class="col-sm-8 <span style="color:red;"></span> <?php if ($fehler["full_name"] != "") { echo 'error'; } ?>
					<label class="control-label"><b><i>Full Given Birth Name</i> *</b></label>
					<input <?php if($cfg['HTML5_error_messages']) { ?> required <?php }else{ ?> onchange="checkField(this)" <?php } ?> aria-label="Full Given Birth Name *" placeholder="Full Given Birth Name *" type="text" style="height:100%;width:100%;" name="full_name" class="field" value="<?php echo $_POST['full_name']; ?>" maxlength="<?php echo $number_of_characters_full_name; ?>">
					<?php if ($fehler["full_name"] != "") { echo $fehler["full_name"]; } ?>
				</div></td>
            </div></tr></table>
<div class="row" id="send">
				<div class="col-sm-8">
					<button type="submit" class="senden" name="en-us-kf-km" style="border: 0; background-color: transparent;" value="Send"/><img src="img/submit.gif" alt="SomeAlternateText"></button>

               </div> 
            </div>		</form>

I am receiving thin plain text (no color no bold no italic):

Full Name : Arun Mishra

These are basic setting:

// form has been sent
if (isset($_POST["en-us-kf-km"]) && $_POST["en-us-kf-km"]) {

	// clean data
    $full_name = stripslashes($_POST["full_name"]);

		// ---- create mail-message for admin
        $mailcontent .= "Full Name / Gender/Sex: " . $full_name . " " . $gender . "\n";
        // ---- send mail to admin
        if($smtp['enabled'] !== 0) {
            require_once __DIR__ . '/smtp.php';
            $success = SMTP::send(
                $smtp['host'],
                $smtp['user'],
                $smtp['password'],
                $smtp['encryption'],
                $smtp['port'],
                $email,
                $yourname,
                $recipient,
                $subject,
                $mailcontent,
                (2==$cfg['UPLOAD_ACTIVE'] ? array() : $uploadedFiles),
                $cfg['UPLOAD_FOLDER'],
                $smtp['debug']
            );
        } else {
            $success = sendMyMail($email, $first_name." ".$name, $recipient, $subject, $mailcontent, $attachments);
        }
<?php
function sendMyMail($fromMail, $fromName, $toMail, $subject, $content, $attachments=array()){

	$boundary = md5(uniqid(time()));
	$eol = PHP_EOL;

	// header
	$header = "From: =?UTF-8?B?".base64_encode(stripslashes($fromName))."?= <".$fromMail.">".$eol;
	$header .= "Reply-To: <".$fromMail.">".$eol;
	$header .= "MIME-Version: 1.0".$eol;
	if(is_array($attachments) && 0<count($attachments)){
		$header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"";
	}
	else{
		$header .= "Content-type: text/plain";
	}
	// subject
	$subject = "=?UTF-8?B?".base64_encode($subject)."?=";

	// send mail
	return mail($toMail, $subject, $message, $header);
}

?>

All this stuff is before ‘head’ tag and ‘form’ is in ‘body’ tag.
Hope this is clear.

  1. I have already posted a section of PHPMailer.php file which very massive file.

  2. There is a config.php which does not have anything relevent.

  3. There are only 2 issues for me - 1) I am not getting special characters ® ™ if it is within ‘input’ field, and 2) Name in bold, italic and color.
    Lastly, if it is allowed, I can post the link where I got this form from so anyone can analyze the issue and trace out the problem point.
    I appreciate your support and help to me.

Then $mailcontent is the line where you would add style to to your liking.
Not sure what you are looking for. Something like this maybe?

$mailcontent .= '<b>Full Name / Gender/Sex:</b> <span style="color:#ff0000;">' . $full_name . ' ' . $gender . "</span>\n";

I tried and tested. But same plain text in black color.

Again I am going to have to side with droopsnoot in post #25 in that your code is using mail() and not phpmailer. With phpmailer you would have things like this along with things defined both before and after these lines.

$mail->Subject = $subject;
$mail->Body    = $mail_body;
$mail->IsHTML(true);

Look at examples at github.com for how to use phpmailer.
https://github.com/PHPMailer/PHPMailer/blob/master/examples/smtp.phps

I found out this code in PHPmailer.php

    public function isHTML($isHtml = true)
    {
        if ($isHtml) {
            $this->ContentType = static::CONTENT_TYPE_TEXT_HTML;
        } else {
            $this->ContentType = static::CONTENT_TYPE_PLAINTEXT;
        }
    }

I hope you will use phpmailer as you will fine it more reliable as far as messages being received etc. I know you can send html emails with mail() as years ago I had a site that had that. The client at that time wanted plain-text and html versions and I modified some of that old code you could try as a stand-alone page just to test. This is untested and I don’t even have hosting anymore that allows mail() or I would have checked it first.

<?php
$to = "";	
$DomainEmail = "";
$subject = "";

$full_name = "Drapm";
$gender = "Male";

$text_content = 'Full Name / Gender/Sex: ' . $full_name . ' ' . $gender . "\n";

$html_content = '<html>
	<head>
		<title>'.$subject.'</title>
	</head>
	<body>
		<b>Full Name / Gender/Sex:</b> <span style="color:#ff0000;">' . $full_name . ' ' . $gender . '</span>
	</body>
</html>';

	# Setup mime boundary
	$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x';

	$headers  = "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n";
	$headers .= "Content-Transfer-Encoding: 7bit\r\n";

	$body	 = "This is a multi-part message in mime format.\n\n";

	# Add in plain text version
	$body	.= "--$mime_boundary\n";
	$body	.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
	$body	.= "Content-Transfer-Encoding: 7bit\n\n";
	$body	.= $text_content;
	$body	.= "\n\n";

	# Add in HTML version
	$body	.= "--$mime_boundary\n";
	$body	.= "Content-Type: text/html; charset=\"UTF-8\"\n";
	$body	.= "Content-Transfer-Encoding: 7bit\n\n";
	$body	.= $html_content;
	$body	.= "\n\n";

	# End email
	$body	.= "--$mime_boundary--\n"; # <-- Notice trailing --, required to close email body for mime's

	# Finish off headers
	$headers .= "From: $DomainEmail\r\n";
	$headers .= "Reply-To: $DomainEmail\r\n";
	$headers .= "X-Sender: $DomainEmail \r\n";
	$headers .= "X-Priority: 3 \r\n";
	$headers .= "X-Mailer: php\r\n";

	# Mail it out
	//echo $body;
	mail($to, $subject, $body, $headers);
?>
1 Like

This line in your code is a clue:

$header .= "Content-type: text/plain";

You’re sending a plain text email, so it doesn’t matter what HTML you put around it, it’ll come out as plain text.

@Drummin has answered in more detail, but PHPMailer would make things easier. Your code does seem to include the header for it, and it’s no wonder that you’ve found HTML email support inside that file, but you’re still using the mail() function. It seems as if whoever wrote the script (I think you said earlier you’d downloaded it from somewhere as opposed to writing it yourself) had started to implement it, then changed their mind for some reason.

Unless the $smtp['enabled'] flag is actually non-zero and you’re sending the email using SMTP::send() instead. Can you show the code for that please, and confirm whether $smtp['enabled'] is non-zero?

I still don’t understand how you’re getting anything inside the email, as the $message variable seems to be undefined inside your sendmymail() function. Even if you’re using SMTP::send() and it’s actually the $mailcontent variable that’s being sent, the code defines a string that starts "Full Name / Gender/Sex: " but the mail you receive contains a string that starts "Full Name : " without reference to Gender or Sex.

  1. I changed email sent option to SMTP and set it. It is working fine. Now please suggest what to change in header in place of text/plain ?

  2. Special characters of ®™ are coming in email.

  3. Now to get color, bold and italic in email.

Thank you all for such an awesome help.
Best regards,
Arun

'Content-type: text/html; charset=iso-8859-1'

$mailcontent .= '<b>Full Name / Gender/Sex:</b> <span style="color:#ff0000;">' . $full_name . ' ' . $gender . "</span>\n";

It did not work.

Did it send the email?

Also make the content html.

$mailcontent .=  '<html>
	<head>
		<title>'.$subject.'</title>
	</head>
	<body>
		<b>Full Name / Gender/Sex:</b> <span style="color:#ff0000;">' . $full_name . ' ' . $gender . '</span>
	</body>
</html>';

Yes. It did but I got everything in normal font and black color.

It too didn’t work.