简体   繁体   English

如何将值从html表单发送到表PHP中的邮件

[英]How to send values from html form to mail in table PHP

This what I have I tried to put it in a table just like: 我曾尝试将其放在表格中,如下所示:

<table>
<tr><td>$_POST['onderwerp']</td></tr>
</table>

This is what I have it sends the mail but it's to messy: 这就是我发送邮件的内容,但是很混乱:

<?php

$to      = 'example@gmail.com';

$subject = 'Vraag via de website';

$message = 'Onderwerp:'. $_POST['onderwerp'].'<br /><br />'.$_POST['vraag'].'<br /><br />'.'Telefoonummer:'. $_POST['tel'].'<br /><br />'.'Email:'. $_POST['email'] ;



$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";



// Additional headers

$headers .= 'To:<eexample@gmail.com>' . "\r\n";

$headers .= 'The shop<example@gmail.com>' . "\r\n";





mail($to, $subject, $message, $headers);

header('Location: contact.html');

?>

I just want to send the variables in a table so that I don't have to search through all the text. 我只想将变量发送到表中,这样就不必搜索所有文本。

<?php
$to = 'user@example.com';
$subject = 'Vraag via de website';
$msg = "<html>
 <head>
 <title>Title of email</title>
 </head>

 <body>

<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">

<tr>
<td align=\"center\">Onderwerp</td>
<td align=\"center\"> vraag</td>
<td align=\"center\">Telefoonummer</td>
<td align=\"center\">Email</td>
</tr>

<tr>
<td align=\"center\">".$_POST['onderwerp']."</td>
<td align=\"center\">".$_POST['vraag']."</td>
<td align=\"center\">".$_POST['tel']."</td>
<td align=\"center\">".$_POST['email']."</td>
</tr>



</table>
</body>
</html>";

// Make sure to escape quotes

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <me@mysite.com>' . "\r\n";

mail($to, $subject, $msg, $headers);

?> 

you could try this using your variables. 您可以使用变量尝试此操作。

$var = 'test';
$var2 = 'test2';

echo '<table border="1">';
echo '<tr><td>' . $var . '</td></tr>';
echo '<tr><td>' . $var . '</td></tr>';
echo '</table>';

this will show the variables in a table, then you can edit the table using css how you want. 这将在表中显示变量,然后您可以根据需要使用CSS编辑表。 :) :)

I suggest that you include swiftmailer. 我建议您包括swiftmailer。 Swiftmailer makes sure emails get delivered in the Inbox and you can easily include HTML markup in your emails: Swiftmailer确保电子邮件在收件箱中传递,并且您可以轻松地在电子邮件中包括HTML标记:

Swiftmailer HTML in email 电子邮件中的Swiftmailer HTML

Just download the Swiftmailer Library, include and configure it like this example: 只需下载Swiftmailer库,像下面的示例一样包含并配置它:

Sending an email in swiftmailer 在swiftmailer中发送电子邮件

Let me know if this helps you out! 让我知道这是否对您有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM