首页 > 解决方案 > Swift 邮件头

问题描述

我有以下 Swift Mailer PHP 例程

<?php
$sname = "First Last";
$sstartdate = "02/02/2020";
$senddate = "02/29/2020";

    $message .= '<p><strong>CAMP REGISTRATION EMAIL CONFIRMATION</strong></p>';
    $message .= '<p><strong>Camp:</strong>' . $sname . '<br>';
    $message .= '<strong>Dates:</strong>' . $sstartdate . ' thru ' . $senddate . '</p>';
    $message .= '<p>This email confirms your registration for the above camp, retreat or conference.</p><p style="color: red;">Please remember that a copy of the applicant insurance card and a copy of the applicant immunization records must can be sent to us by mail to: 333 Cedine Camp Road, Spring City, TN 37381, or emailed to us at confreg@cedine.org. Please include your child\'s full name and the name and dates of the camp they are attending.</p><p style="color: red;">Your registration is not complete until your camp fees have been received.</p><p style="text-align: left; font-size: 11px;">' . date('D, m-d-Y, h:i:s a') . '</p>';
    $message .= '<p><a href="https://www.cedine.org">Cedine Ministires</a></p>';



print "<hr>$message</hr>";

// send emails 
// https://swiftmailer.symfony.com/docs/sending.html
// tls = 587 or 465
    require_once ("../swift/lib/swift_required.php");
    $emails = array('jsnull@outlook.com');
    //$themessage = "<p><strong>Cedine Website</strong></p>";

    foreach ($emails as $email){
            $transport = Swift_SmtpTransport::newInstance('mail.authsmtp.com', 587, 'tls')
                 ->setUsername('xxxxxxxxxxxxxxx')
                 ->setPassword('xxxxxxxxxxxxxxxxxxx');

            $mailer = Swift_Mailer::newInstance($transport);

            $message = Swift_Message::newInstance('Registration Email From Website')
                  ->setFrom(['info@cedine.org' => 'Cedine Registration'])
                  ->setTo(array($email))
                  ->setBody($message, 'text/html');

            $mailresult = $mailer->send($message);
    }

print "<hr>$message</hr>";

?>

代码添加后显示 $message

消息 ID:日期:2020 年 2 月 24 日星期一 11:51:42 -0500 主题:注册电子邮件 来自网站的发件人:Cedine 注册收件人:jsnull@outlook.com MIME 版本:1.0 内容类型:text/html;charset=utf-8 内容传输编码:quoted-printable

到 $message ...我该如何防止这种情况?

见:https ://cedine.org/register/testemails.php

标签: phpswiftmailermailer

解决方案


我通过改变这个解决了我自己的问题......

$message = Swift_Message::newInstance('Registration Email From Website')
              ->setFrom(['info@cedine.org' => 'Cedine Registration'])
              ->setTo(array($email))
              ->setBody($message, 'text/html');

对此……

$newmessage = Swift_Message::newInstance('Registration Email From Website')
              ->setFrom(['info@cedine.org' => 'Cedine Registration'])
              ->setTo(array($email))
              ->setBody($newmessage, 'text/html');

推荐阅读