【问题标题】:Problem with layout of mail in my contact form我的联系表格中的邮件布局有问题
【发布时间】:2020-09-28 11:49:45
【问题描述】:

我的联系表单布局需要帮助,这是我的问题:

当我收到来自我的联系表单的邮件时,我的 /r 或 /n 似乎不起作用我将表单的所有内容放在一行中,我不知道为什么。

这是我的代码:

<?php

if (isset($_POST)) {

    $lastName = $_POST['lastName'];
    $firstName = $_POST['firstName'];
    $speciality = $_POST['speciality'];
    $adress = $_POST['adress'];
    $phone = $_POST['phone'];
    $mailFrom = $_POST['email'];
    $txt = $_POST['message'];

    $to = "mymail@mymail.com";
    $subject = utf8_decode("Expéditeur : ".$lastName." ".$firstName);
    $message = 'Vous avez reçu un email de ' . $lastName . "\r\n" .  $firstName . "\r\n" . $speciality . "\r\n" . $adress . "\r\n" . $phone . "\r\n" . $mailFrom . "\r\n" .$txt;
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: '.$mailFrom."\r\n";
    $headers .= 'Reply-To: '.$mailFrom."\r\n";

    mail($to, $subject, $message, $headers);
    header("Location: /");
}

请任何人帮助我。非常感谢。

【问题讨论】:

  • \r\n 仅适用于文本邮件(或者,如果您查看 HTML 邮件的来源)。如果您发送 HTML 邮件(或发送文本邮件),您应该使用 &lt;br&gt;
  • 这能回答你的问题吗? php mail () /r/n and <br> have no effect
  • Tk 你们现在都很好:D

标签: php forms layout


【解决方案1】:

您只需将"\r\n" 更改为html &lt;br&gt; 标签

<?php

    if (isset($_POST)) {

        $lastName = $_POST['lastName'];
        $firstName = $_POST['firstName'];
        $speciality = $_POST['speciality'];
        $adress = $_POST['adress'];
        $phone = $_POST['phone'];
        $mailFrom = $_POST['email'];
        $txt = $_POST['message'];

        $to = "mymail@mymail.com";
        $subject = utf8_decode("Expéditeur : ".$lastName." ".$firstName);

        $message = ' 
          <html> 
            <head> 
                <title>Welcome to Website Name</title> 
            </head> 
            <body>

            <p> Vous avez reçu un email de '. $lastName .'<br>'.  $firstName .'<br>'. $speciality .'<br>'. $adress .'<br>'. $phone .'<br>'. $mailFrom .'<br>'. $txt .'</p>

            </body> 
          </html>
        ';

        $headers = "MIME-Version: 1.0" . "\r\n"; 
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= 'From: '.$mailFrom."\r\n";
        $headers .= 'Reply-To: '.$mailFrom."\r\n";

        mail($to, $subject, $message, $headers);
        header("Location: /");
    }

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多