Skip to content
Advertisement

PHPMailer won’t send html message with media queries [closed]

I am using PHPmailer to send emails.

php 7.4
phpmailer 5.2
thunderbird - emailclient 78

tiny for email body

UPDATE 1 both tiny and thunderbird for security reasons removes @media

I have a responsive e-mails with media queries. E-mails come from MySql database. I can send e-mails but after sending phpmailer romemoves media queries. I tested on 2 SMTP mail servers – the same result.

My code looks like this.

send_emai.php

    $body_id = $_POST['body_id'];

    $res2 = mysqli_query($con,"select * from news_body where id='$body_id'");
    $row = mysqli_fetch_assoc($res2);
    $mail_body = $row['description'];

    smtp_mailer($email,$mail_subject,$mail_body);

function smtp_mailer($to,$subject,$msg) {
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SetFrom("syrius@xxxx");
    $mail->Host             =   "xxxx";
    $mail->Port             =   465;
    $mail->SMTPSecure       =   "ssl";
    $mail->SMTPAuth         =   true;
    $mail->Username         =   "xxxx";
    $mail->Password         =   'xxxx';

    $mail->Subject = $subject;
    $mail->Body = $msg;
    $mail->AddAddress($to);
    $mail->IsHTML(true);
    $mail->SMTPOptions=array('ssl'=>array(
        'verify_peer'=>false,
        'verify_peer_name'=>false,
        'allow_self_signed'=>false
    ));
    if(!$mail->Send()){
        //echo $mail->ErrorInfo;
    }else{
        //echo 'Sent';
    }
}

email before sending

@media only screen and (max-width: 660px) {....

after sending
there is nothing, code has been removed

Advertisement

Answer

You have a bias in your question, you assume this has to do with PHPMailer. You disregard your own mailserver, the receiving mailserver and the receiving mailclient. Especially the last could be the culprit.

For instance if you are using Thunderbird.

But other email clients could change the content of emails as well. This is usually done for security reasons.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement