guitarlass
guitarlass

Reputation: 1617

Why html not showing in the email i sent using php mail() function?

I sent email confirmation massage using php mail() function but it's not processing html tags . have any idea why?

   $content="Dear $name, <br /><br />Thank you for registering at NAME. Before we can activate your account one last step must be taken to confirm your email address .";
            $content.="<br /><br />Please note - you must complete this last step. You will only need to visit this URL once to confirm your email address.<br /><br />To complete your registration,";
            $content.=" please visit this URL:<br /><a href='$link1' target='_blank'> $link1 </a><br /><br /><br />";
            $content.="If you are still having problems signing up please contact a member of our support staff at&nbsp;<a href='mailto:[email protected]'>email</a> or contact our <a href='$link2'>customer care</a>. <br /><br />";
            $content.="All the best,<br />NAME<br />";
            mail($custArray['email'],"Please Confirm Your Email",$content);

Upvotes: 0

Views: 2296

Answers (4)

mac
mac

Reputation: 1

$headers  = "From: $email\r\n" . "Reply-To: $email\r\n" . "CC: $cc\r\n";

$message  = "$logmsg \r\n\n";
$message .= "Name : $name \r\n\n";
$message .= "Email : $email \r\n\n";
$message .= "Phone No : $phone \r\n\n";

Upvotes: 0

Michal Charemza
Michal Charemza

Reputation: 27012

You can consider using an external library to handle HTML email. I've used http://swiftmailer.org/ successfully in the past.

Upvotes: 1

reergymerej
reergymerej

Reputation: 2417

You need to specify in the header that this is an html email so it will be interpreted as html rather than plain text.

http://php.net/manual/en/function.mail.php

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$content="Dear $name, <br /><br />Thank you for registering at NAME. Before we can activate your account one last step must be taken to confirm your email address .";
$content.="<br /><br />Please note - you must complete this last step. You will only need to visit this URL once to confirm your email address.<br /><br />To complete your registration,";
$content.=" please visit this URL:<br /><a href='$link1' target='_blank'> $link1 </a><br /><br /><br />";
$content.="If you are still having problems signing up please contact a member of our support staff at&nbsp;<a href='mailto:[email protected]'>email</a> or contact our <a href='$link2'>customer care</a>. <br /><br />";
$content.="All the best,<br />NAME<br />";
mail($custArray['email'],"Please Confirm Your Email",$content, $headers);

Upvotes: 3

Gohn67
Gohn67

Reputation: 10648

You probably need to add the headers for an html email. Here is the example from the php website ( http://php.net/manual/en/function.mail.php):

// 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";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

Upvotes: 3

Related Questions