Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设计php电子邮件表单正文的样式?_Php_Html_Css_Email - Fatal编程技术网

如何设计php电子邮件表单正文的样式?

如何设计php电子邮件表单正文的样式?,php,html,css,email,Php,Html,Css,Email,我正在尝试创建一个php表单。当我通过电子邮件收到提交的表格时,我应该会看到它的外观很好 如果把下面的代码我得到这个![电邮正文][1] $mailBody=" <html> <body> <table border=\"1\" style=\"width:100%\"> Name: $name_title $sender\n

我正在尝试创建一个php表单。当我通过电子邮件收到提交的表格时,我应该会看到它的外观很好

如果把下面的代码我得到这个![电邮正文][1]

$mailBody=" <html>
                <body>
                    <table border=\"1\" style=\"width:100%\">
                        Name: $name_title $sender\n
                        Email: $senderEmail\n\n
                        $message
                    </table>        
                </body>
            </html>";
$mailBody=”
名称:$Name\u title$sender\n
电子邮件:$senderEmail\n\n
$message
";

当我得到我的php表单时,如何才能得到一个像html文档一样的好的scc表或div?

在设置电子邮件表单输出样式时,您不需要使用

您只需要从table元素开始,并使用一些内联样式。下面的代码将给出一个简单的表格,用粗体显示姓名和电子邮件标签,每个单元格周围有一个小的填充

$mailBody = "<table style='width:100%' cellpadding='5'>
                 <tr>
                     <td style='font-weight:bold;'>Name:</td><td>$name_title $sender</td>
                 </tr>
                 <tr>
                     <td style='font-weight:bold;'>Email:</td><td>$senderEmail</td>
                <tr>
                     <td colspan=2>$message</td>
                </tr>
            </table>";

请试试这个

<?php

    if($_POST["submit"]) {
    $recipient="am.riparz@gmail.com";
    $subject="Arugambay Bookings : New reservations request";
    $sender=$_POST["sendername"];
    $senderEmail=$_POST["senderEmail"];
    $message=$_POST["message"];
    $name_title=$_POST["name_title"];   

    $mailBody = "<table style='width:100%' cellpadding='5'>";
    $mailBody .= "<tr>";
    $mailBody .= "<th>Item</th>";
    $mailBody .= "<th>Description</th>";
    $mailBody .= "</tr>";
    $mailBody .= "<tr>";
    $mailBody .= "<td>Name</td>";
    $mailBody .= "<td>$name_title $sender</td>";
    $mailBody .= "</tr>";
    $mailBody .= "<tr>";
    $mailBody .= "<td>Email</td>";
    $mailBody .= "<td>$senderEmail</td>";
    $mailBody .= "</tr>";
    $mailBody .= "<tr>";
    $mailBody .= "<td>Special req</td>";
    $mailBody .= "<td>$message</td>";
    $mailBody .= "</tr>";
    $mailBody .= "</table>";

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
    }

    if ($mail_sent) {
?>


    <p>Mail sent</p>
 <?php } ?

发送的邮件


您无需在消息体中添加或标记,只需使用内联css编写普通html代码即可。您只需添加内联cssKeep即可。记住,并非所有人都会看到html布局。人们可以决定在所有邮件中使用纯文本。你能在不添加css的情况下发送邮件吗?是的。。实际上这是我的电子邮件。我想把表格的细节弄清楚。因此,我可以清楚地阅读它,并根据我收到的HTML邮件安排事情。如果只是添加CSS,那么我如何才能使它在2行。我需要在左边得到姓名标签,在右边输入。请至少在mail()函数中添加标题。所有那些
$msg.=
看起来真的很难看。。。但会起作用。谢谢你,但上面说的是语法错误。意外的T变量。你能检查一下我编辑过的答案吗@我找到了。我遗漏了一些分号;任何关于我的结果是抱歉的4晚回复@RiffazStarr我已经编辑了我的答案。试试看!干杯,谢谢你。但是如果我从
$mail\u sent=mail($recipient,$subject,$mailBody,“from:$sender”,$headers)中删除
$headers
然后它会将邮件以HTML代码的形式发送到电子邮件,就像previuos一样。视觉效果不好。如果使用
$mail\u sent=mail($recipient,$subject,$mailBody,“From:$sender”,$headers)它没有发送邮件。对不起,我不明白这是怎么回事。它解决了OP提出的问题。没有什么太复杂的,并且会按照他或她想要的方式工作。所以,如果你认为我的回答有严重的错误,请你提醒我一下好吗?你的回答只是一个提示,不是很好。你没有提到Riffaz Starr没有使用正确的mime封装或标题,这就是他在电子邮件中看到原始HTML的原因。我非常感谢你的输入,但是你问了问题,我回答了,没什么。我得到了解析错误:语法错误,意外的T_变量,我已经找到了原因。这是因为右上方的。还没关。如何将$headers放在哪里?现在这只是一个变量。不打印任何内容OK更新您的答案。谢谢。现在的问题是添加MIME版本头。如果我使用
$mail\u sent=mail($recipient,$subject,$mailBody,“From:$sender”)那就好了。它将邮件发送到电子邮件。如果我使用
$mail\u sent=mail($recipient,$subject,$mailBody,“From:$sender”,$headers)则它不发送邮件。可能是因为我在wordpress网站的边栏上使用了这个。编辑我的问题的人删除了wordpress这个词。有什么建议吗?你好,里法兹,你发送邮件的方式是正确的。但是我的建议是使用SMTP身份验证而不是这个。因为如果您通过php邮件功能发送邮件,这将是垃圾邮件。我已经给你发了链接。这对你将来可能会有很大帮助。
<?php

$to  = "some@example.comsome1@exmple.com,some3@example.com";
$subject = 'Hello World';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// More headers
$headers .= 'From: <me@some.com>' . "\r\n";

$msg =   '<html>';
$msg .= '<head>
   <h2 style="font-family:verdana;text-align:center;background-color:red">Hello World</h2>
   </head>
  <table border="3" cellspacing="2">
  <tr style="font-family:verdana;background-color:#6d6d6d">
       <th>col1</th>
       <th>col2</th>
       <th>Col3</th>
       <th>Col4</th>
   </tr>';
//do something here fetch or send static body

$msg .= "<tr>";
$msg .="<td>" . fetch from db/or static body. "</td>";
$msg .= "<td>" .fetch/ static. "</td>";
$msg .= "<td>" .fetch/static  . "</td>";
$msg .= "</tr>";

$msg .= '</table>';      
$msg .= '</html>'; 

mail($to, $subject, $msg, $headers); 
?>
<?php

    if($_POST["submit"]) {
    $recipient="am.riparz@gmail.com";
    $subject="Arugambay Bookings : New reservations request";
    $sender=$_POST["sendername"];
    $senderEmail=$_POST["senderEmail"];
    $message=$_POST["message"];
    $name_title=$_POST["name_title"];   

    $mailBody = "<table style='width:100%' cellpadding='5'>";
    $mailBody .= "<tr>";
    $mailBody .= "<th>Item</th>";
    $mailBody .= "<th>Description</th>";
    $mailBody .= "</tr>";
    $mailBody .= "<tr>";
    $mailBody .= "<td>Name</td>";
    $mailBody .= "<td>$name_title $sender</td>";
    $mailBody .= "</tr>";
    $mailBody .= "<tr>";
    $mailBody .= "<td>Email</td>";
    $mailBody .= "<td>$senderEmail</td>";
    $mailBody .= "</tr>";
    $mailBody .= "<tr>";
    $mailBody .= "<td>Special req</td>";
    $mailBody .= "<td>$message</td>";
    $mailBody .= "</tr>";
    $mailBody .= "</table>";

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $mail_sent = mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
    }

    if ($mail_sent) {
?>


    <p>Mail sent</p>
 <?php } ?