【问题标题】:Phpmailer sending email as plain text to emailsPhpmailer 将电子邮件作为纯文本发送到电子邮件
【发布时间】:2022-01-26 12:53:00
【问题描述】:

我第一次遇到 phpmailer 的问题,有人知道为什么 phpmailer 会发送如下电子邮件吗?它以某种方式没有将电子邮件转换为 html contecn 我似乎无法弄清楚为什么会发生这种情况

no=reply@domain.com
6:16 PM (0 minutes ago)
to me

--b1_948b9a2ff8436cf0db01abf3e30c0373
Content-Type: text/plain; charset=us-ascii


Request information form was submitted, details are given below.




                        Name
                        Email
                        Mobile
                        State
                        Plans
                        Destination
                        Total Travellers
                        Travel Within
                        Comments


                        debojit
                        no@email.com
                        451-245-7845
                        Georgia
                        Bags packed, I'm ready to go!
                        France
                        9 people
                        6-9 months
                        werwer




Regards,

company name



--b1_948b9a2ff8436cf0db01abf3e30c0373
Content-Type: text/html; charset=us-ascii


<h4>Request information form was submitted, details are given below.</h4>
<br/>
        <table border="1" style="width:100%">
        <tbody>
                <tr>
                        <td><b>Name</b></td>
                        <td><b>Email</b></td>
                        <td><b>Mobile</b></td>
                        <td><b>State</b></td>
                        <td><b>Plans</b></td>
                        <td><b>Destination</b></td>
                        <td><b>Total Travellers</b></td>
                        <td><b>Travel Within</b></td>
                        <td><b>Comments</b></td>
                </tr>
                <tr>
                        <td>debojit</td>
                        <td>no@email.com</td>
                        <td>451-245-7845</td>
                        <td>Georgia</td>
                        <td>Bags packed, I'm ready to go!</td>
                        <td>France</td>
                        <td>9 people</td>
                        <td>6-9 months</td>
                        <td>werwer</td>
                </tr>
        </tbody>
</table>               
<br/><br/>
Regards,
<br/>
company name



--b1_948b9a2ff8436cf0db01abf3e30c0373--

这就是我发送邮件的方式

$mail = new Mail();
$mail->setFrom(senderemail);
$mail->addAddress(email);
$mail->addReplyTo($email);
$mail->subject($subject);
$mail->body($body);
//$mail->send();      
if($mail->send()){
     echo '<div class="alert alert-success" role="alert">Thanks for contacting us, we\'ll get back to you soon.</div>';
     echo "<meta http-equiv='refresh' content='5;url=contact-us.php'>";

    }else{
     echo '<div class="alert alert-danger" role="alert">Some problem occurred, please <a href="contact-us.php">try again</a>.</div>';
    echo "<meta http-equiv='refresh' content='5;url=contact-us.php'>";
  }
}   

我尝试添加 $mail->IsHTML(true);等等,但似乎没有任何效果,这里可能有什么问题?

【问题讨论】:

  • 这能回答你的问题吗? PHPmailer sending HTML CODE
  • @Justinas 我也尝试了该帖子中的步骤,但它没有解决我的问题,这就是我创建此帖子的原因。我从来没有遇到过这个问题。
  • 通过添加 smtp 登录详细信息对其进行排序

标签: php email phpmailer


【解决方案1】:

这是完全虚构的,与有效的 PHPMailer 代码只有很小的相似之处——它甚至不是有效的 PHP!除非你使用了一个你没有告诉我们的包装器/子类?

$mail = new Mail();
$mail->setFrom(senderemail);
$mail->addAddress(email);
$mail->addReplyTo($email);
$mail->subject($subject);
$mail->body($body);

PHPMailer 类被称为PHPMailer,而不是Mail。使用Subject 属性设置主题;没有subject()这样的方法。同样,没有body()这样的方法;设置主体设置Body 属性。总的来说应该是:

$mail = new PHPMailer();
$mail->setFrom($senderemail);
$mail->addAddress($email);
$mail->addReplyTo($email);
$mail->Subject = $subject;
$mail->Body = $body;

PHPMailer 不做任何 HTML 转换。创建作为邮件正文的一部分发送的 HTML 完全取决于您,并且您还必须告诉它您正在使用 HTML,例如:

$mail->isHTML();
$mail->Body = '<h1>Lovely HTML</h1>';
$mail->AltBody 'boring plain text';

所有文档和示例都向您展示了这一点,所以也许您应该阅读它们。

【讨论】:

  • 通过添加 smtp 登录详细信息对其进行排序
  • 这毫无意义!如果您的凭据错误,则根本不会交付任何东西!
【解决方案2】:

问题已通过启用 smtp 登录详细信息解决

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    相关资源
    最近更新 更多