php - html email issue for a tag value


I am sending html email to the client via php mail function. while & sign shown in bold creating problems in email replacing ! %20 something like characters within my ids such as below(in bold).**!**1234&cat_id=23

Below is my code. $to = '[email protected]';

// subject
$subject = 'test';

 $message.='<html><head><meta charset="UTF-8" /></head><body><p><a href="" target="_blank">Wine **&** Dine Offers</a></p></body></html>';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

// Additional headers
$headers .= 'To: test <[email protected]>' . "\r\n";
$headers .= 'From: test user <[email protected]>' . "\r\n";

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

After sending mail i am getting ! and %20 like characters in email. I also tried & except & in email but no use still ! adding within my email html.




I think you should encode the URL on the email. Plus, you probable have magic_quotes_gpc "on" that is not recommended.

I always use PHPMailer, it saves a lot of work and helps on these problems




try this:

$toName  = 'test'; 
$toAddress  = '[email protected]'; 

$fromName  = 'test user'; 
$fromAddress  = '[email protected]'; 

// subject
$subject = 'test';

// URL for link
// this should have any URL encoded characters literally in the string
$url = '';

// HTML for message
// Call htmlspecialchars() on anything that may need it (like the URL)
$messageHTML = '<html><head><meta charset="UTF-8" /></head><body><p><a href="'.htmlspecialchars($url).'" target="_blank">Wine &amp; Dine Offers</a></p></body></html>';

// Text version of message
// Remember, not everyone has an HTML email client!
$messageText = "Wine & Dine Offers: $url";

// Build a multipart MIME message
$boundary = '------'.md5(microtime()).'------';
$body =
"This is a multipart message in MIME format.\r\n"
."Content-Type: text/plain\r\n"
."Content-Type: text/html; charset=UTF-8\r\n"

// To send HTML mail, the Content-type header must be set correctly
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative; boundary=\"$boundary\"\r\n";

// Additional headers 
// the To: header will be set by mail() and is not required here
$headers .= "From: $fromName <$fromAddress>\r\n";

// Mail it
mail("$toName <$toAddress>", $subject, $body, $headers); 

People are also looking for solutions to the problem: php - Creating Dynamic Acl in Zend - Framework (check list for acl)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.