PHPMailer发送的附件显示在HTML内容后面

时间:2019-02-14 08:01:30

标签: php email phpmailer

我正在使用phpmailer 6.0.7发送邮件。收到的邮件显示如下:

Presentation in iOS Mail-App

我希望附件在邮件内容的底部。我的代码中有什么要考虑的吗?我的代码如下:

$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->setFrom($user->get_mail(), utf8_decode($user->get_vorname()." ".$user->get_nachname()));
$mail->AddAddress($sr->get_mail(), utf8_decode($sr->get_vorname()." ".$sr->get_name()));
$mail->addReplyTo($user->get_mail(), $user->get_vorname()." ".$user->get_nachname());
$mail->IsHTML(true);
$mail->Subject = $betreff;
$mail->Body = getMailHTML(str_replace("\n", "<br/>", $mailBody), $foot);
$mail->addAttachment($file);
$mail->send();

编辑 这是我的HTML正文:

function getMailHTML($body, $foot){

    $output = "<!DOCTYPE html>
                    <html>
                        <head>
                            <meta charset=\"UTF-8\">
                            <title>SR-Ausschuss Online</title>
                            <style>
                            @font-face { font-family: \"Source Sans Pro\"; font-style: normal; font-weight: 400; src: local(\"Source Sans Pro Regular\"), local(\"SourceSansPro-Regular\"), url(\"https://fonts.gstatic.com/s/sourcesanspro/v11/6xK3dSBYKcSV-LCoeQqfX1RYOo3qOK7l.woff2\") format(\"woff2\"); unicode-range: U+0-FF, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
                            @font-face { font-family: \"Source Sans Pro Light\"; font-style: normal; font-weight: 300; src: local(\"Source Sans Pro Light\"), local(\"SourceSansPro-Light\"), url(\"https://fonts.gstatic.com/s/sourcesanspro/v11/6xKydSBYKcSV-LCoeQqfX1RYOo3ik4zwlxdu.woff2\") format(\"woff2\"); unicode-range: U+0-FF, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
                            @font-face { font-family: \"Source Sans Pro Bold\"; font-style: normal; font-weight: 700; src: local(\"Source Sans Pro Bold\"), local(\"SourceSansPro-Bold\"), url(\"https://fonts.gstatic.com/s/sourcesanspro/v11/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2\") format(\"woff2\"); unicode-range: U+0-FF, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
                            .head{
                                position: absolute; 
                                left: 0px; 
                                top: 60px; 
                                height: 50px; 
                                width: 100%; 
                                font-size: 35px;
                            }
                            .heading{
                                position: absolute; 
                                left: 10px; 
                                top: 0px; 
                                line-height: 50px; 
                                font-size: 35px; 
                                color: #333;
                                font-family: 'Source Sans Pro Light';
                            }

                            .heading b{
                                font-family: 'Source Sans Pro Bold';
                            }

                            .container{
                                float: left;
                                position: absolute;
                                top: 120px;
                                left: 0px;
                                margin: 10px;
                                background-color: #fff;
                                padding: 20px;
                                width: -webkit-calc(100% - 60px);
                                width: -moz-calc(100% - 60px);
                                width: calc(100% - 60px);
                            }

                            .body{
                                width: -webkit-calc(100% - 30px);
                                width: -moz-calc(100% - 30px);
                                width: calc(100% - 30px);
                                font-family: 'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif; 
                                font-weight: 400; 
                                font-size: 14px; 
                                margin-left: 10px;
                                margin-right: 10px;
                                margin-top: 10px;
                                margin-bottom: 10px;
                                float: both;
                                min-height: 20px;
                            }

                            a.button{
                                float: both;
                                display: block;
                                text-decoration: none;
                                width: -webkit-calc(100% - 30px);
                                width: -moz-calc(100% - 30px);
                                width: calc(100% - 30px);
                                margin-right: 10px;
                                margin-top: 10px;
                                margin-bottom: 10px;
                                background-color: #00a65a; 
                                color: #fff;
                                text-align: center;
                                height: 40px;
                                line-height: 40px;
                                font-weight: 600;
                            }

                            .foot{
                                font-weight: 400; 
                                font-size: 14px; 
                                margin-left: 10px; 
                                margin: 10px;
                                float: both;
                                min-height: 20px;
                                width: -webkit-calc(100% - 30px);
                                width: -moz-calc(100% - 30px);
                                width: calc(100% - 30px);
                            }

                            body{
                                -webkit-font-smoothing: antialiased; 
                                -moz-osx-font-smoothing: grayscale; 
                                font-family: 'Source Sans Pro','Helvetica Neue', Helvetica, Arial, sans-serif; 
                                background-color: #d2d6de;
                            }
                            </style>
                        </head>
                        <body>
                            <div class=\"head\">
                                <span class=\"heading\"><b>SR-Ausschuss</b>Online</span>
                            </div>
                            <div class=\"container\">
                                <div class=\"body\">".$body."</div>
                                <div class=\"foot\">".$foot."</div>
                            </div>
                        </body></html>";

    return $output;
}

body和foot是简单的文本变量,没有任何自己的html标记或其他内容。其中只有几个换行符。可以在邮件正文中给附件一个固定的位置吗?

0 个答案:

没有答案