Sagar Singh Sagar Singh - 6 months ago 18
PHP Question

how to send email with multiple Apostrophe & quotation mark in body of email

i have email template which consist of html tags like this

$mail->Body = '<td style="color: #848484; font-size: 14px; font-family: Calibri,
sans-serif, 'Open Sans'; line-height: 18px; border-collapse: collapse;"
align="left">Copyright (C) 2016 example All rights reserved.</td>';


Now if i change 'Open Sans' into "Open Sans" fonts become messy in look & there are more tags in template which consist of Apostrophe

what could be the best way of sending this email template without getting any error

Answer

If you delimit a string literal with single-quotes, and want to use single-quotes inside the string content, you need to escape them with a backslash:

$mail->Body = '<td style="color: #848484; font-size: 14px; font-family: Calibri, 
sans-serif, \'Open Sans\'; line-height: 18px; border-collapse: collapse;" 
align="left">Copyright (C) 2016 example All rights reserved.</td>';

Same thing with double-quotes instead:

$mail->Body = "<td style=\"color: #848484; font-size: 14px; font-family: Calibri, 
sans-serif, 'Open Sans'; line-height: 18px; border-collapse: collapse;\" 
align=\"left\">Copyright (C) 2016 example All rights reserved.</td>";
Comments