0

I'm redoing a PHP form handler to make it responsive and when I changed the code the inline css that I had on the elements before stopped displaying properly. Some of styles work but some of them don't, for instance the padding, the background color etc.

This is the code after I changed it:

      $email_body = "<table width='100%' style='text-align: left; font-family: Arial, sans-serif;'>";
      $email_body .= "<tr style='text-align: center;'><td><h1 style='font-size: 13px;'>New Feedback</h1></td></tr>";
      $email_body .= "<tr style='background-color: #00b1ff !important; color: #fff !important; text-align: center;'><td style='background-color: #00b1ff !important; color: #fff !important;'><h2 style='background-color: #00b1ff; #color: #fff; font-weight: 700; font-size: 14px;'>Location One</h2></td></tr>";
      $email_body .= "<tr style=''><td><p><span style='color: #00b1ff; font-weight: 700;'>Name:</span>$from_name</p></td></tr>";
      $email_body .= "<tr style=''><td><p><span style='color: #00b1ff; font-weight: 700;'>Email:</span>$from_email</p></td></tr>";
      $email_body .= "<tr style=''><td><p><span style='color: #00b1ff; font-weight: 700;'>Phone:</span>$phone_number</p></td></tr>";
      $email_body .= "<tr style=''><td><p><span style='color: #00b1ff; font-weight: 700;'>Message:</span></p></td></tr>";
      $email_body .= "<tr style='color: #000'><td><p>$message</p></td></tr>";
      $email_body .= "<tr style=''><td><p><a style='font-family: Arial, sans-serif; font-weight: 700; background-color: #00B1FF; border-radius: 4px; padding: 10px; color: #fff; text-decoration: none; padding: 20px; color: #fff;' href='mailto:$from_email?subject=Your experience with Feedback'>Respond to $from_name</a></p></td></tr>";
      $email_body .= "<tr style='text-align: center;'><td><p style='font-family: Arial, sans-serif; color: #9c9c9c !important; font-size: 10px !important; width: 100%; text-align: center;'>This is an automated message. Replies to this email will not be checked.</p></td></tr> </table>";
      $header = 'MIME-Version: 1.0' . "\r\n";
      $header .= "Content-type: text/html; charset=iso-8859-1' . \r\n";

And this is what the new changes look like when they come in the email: enter image description here

This is the code as it was before:

    $email_body = "<p align='center' style='color: #ffffff; width: 100%; padding: 20px 50px 20px 50px; background-color: #45ABE0; font-size: 20px; font-weight: 900; font-family: Arial, sans-serif; '>You have received new Feedback from $from_name.</p>";
    $email_body .= "<table style='width: 100%; font-family: Arial, sans-serif; padding-top: 50px;'><tr style='color: #45ABE0; font-weight: 700;'><td>NAME</td><td>EMAIL</td><td>PHONE NUMBER</td></tr>" ;
    $email_body .= "<tr style='color: #333333; '><td>$from_name</td><td style='text-decoration: none;'>$from_email</td><td>$phone_number</td></tr></table>  " ;
    $email_body .= "<p><span style=' color: #45ABE0; font-family: Arial, sans-serif; font-weight: 700;'>MESSAGE</span></p>" ;
    $email_body .= "<p style=' color: #333333; font-family: Arial, sans-serif;'>$message</p>" ;
    $email_body .= "<table style='width: 100%; font-family: Arial, sans-serif; text-align: center;'><tr><p style='font-family: Arial, sans-serif; color: #9c9c9c !important; font-size: 10px !important; width: 100%; text-align: center;'>This is an automated message. Replies to this email will not be checked.</p></tr></table>" ;
    $header  = 'MIME-Version: 1.0' . "\r\n";
    $header .= "Content-type: text/html; charset=iso-8859-1' . \r\n";

And this is what the emails used to look like:

enter image description here

I'm unsure as to why the styles that worked before have stopped working. I am using Spark email client. Am I missing something or did I make a mistake with the new code?

Samson
  • 21
  • 6

1 Answers1

1

Keep in mind that this can be different depending on the client and clients change a lot. for example I had issues similar to what you are facing from the outlook from ios and on windows and other clients too. You have to test and build your html to work in multiple outdated IE based engines.

I suggest you test your code in one of the tools listed in this question: Testing HTML email rendering

I used https://email2go.io/home to fix my layouts.

Hope it helped.

Ricardo Silva
  • 1,221
  • 9
  • 19