Search code examples
phpgmailphpmailer

PHPMailer Gmail summary


How can I make sure that Gmail (and other mediums) use my "text/plain" for the summary (see image below) and the "text/html" version for displaying when sending mails in PHP? Using PHPMailer's altBody did work for me before, but now Gmail only shows the first words used in the "text/html" version instead of using the "text/plain" one.

Gmail messages with "summary"


Solution

  • You can't, it's beyond your control, but you can play to their actions. Gmail. Apple Mail, iOS mail, Outlook and others usually take the first non-markup text they find for that area, which is often referred to as a 'pre-header'. You can add some text to say whatever you like, then hide it in your HTML using CSS, for example:

    ...
    <body>
    <span style="display:none !important;">This will be invisible in the message, but shown in the message preview.</span>
    <p>Dear xxx,</p>
    ...
    

    As you've seen you don't have any control over the length that is displayed - e.g. mobile clients will usually display less than desktop ones - so I'd advise you to keep it short and sweet.