Search code examples
phphtmlemailphpmailerfont-awesome

Font awesome icons not showing in php mailer message body


I am trying to send mail using PHP mailer. Everything is going well, mail is sending with html tags, an image is also embedded. But font awesome icons in the html is not showing in the mail body.

When i tried to echo the message body, it is displaying perfectly. But not in the message body. Following is my code. Message body portion is in bold. Thanks.

require 'phpmailer/class.phpmailer.php';

    $mail = new PHPMailer();
    $mail->SMTPDebug = 2;                               
    $mail->isSMTP();                                      
    $mail->Host = 'smtp.gmail.com';                       
    $mail->SMTPAuth = true;                               
    $mail->Username = '[email protected]';          
    $mail->Password = 'XXXXXXXX';                        
    $mail->SMTPSecure = 'ssl';                            
    $mail->Port = 465;
    $mail->AddReplyTo($email, $cp);
    $mail->From = '[email protected]';
    $mail->FromName = $cp;
    $mail->addAddress('XXXXXXXXXXXXX');     
    $mail->WordWrap = 50;                               
    $mail->isHTML(true);
    $mail->AddEmbeddedImage('images/logo.png', 'logo_2u');
    $mail->Subject = 'Enquiry';

    **$body="<div class='container' id='mail-body'>
            <img class='img-responsive' id='mail-logo' src='cid:logo_2u' width='450'>
                <p style='color: #1f497d;'><i class='fa fa-map-marker'></i> Address here</p>
                <p style='color: #1f497d;'><i class='fa fa-mobile' aria-hidden='true'></i> +XXXXXX <span>|</span> <i class='fa fa-fax' 
                aria-hidden='true'></i> +XXXX <span>|</span> <i class='fa fa-phone' aria-hidden='true'>
                </i> +XXXXX</p>
                <p style='color: #1f497d;'><i class='fa fa-envelope' aria-hidden='true'></i> [email protected] | [email protected]  |  <i class='fa fa-globe' aria-hidden='true'></i> www.mywebsite.com</p>
        </div>";**

        set_time_limit(200);
        $mail->Body    = $body;
        if($mail->Send())
        {
            echo 'mail sent';
        }

Solution

  • When you look at it on your local machine, you have the font installed, so it works, but you can't load the font dynamically in most email clients, so it can't load the font and thus will not render anywhere that the font is not already available.

    Find another way - embed images probably the easiest.

    Also don't expect complex CSS to work reliably in email either.