我试图以表格形式将用户输入发送到邮件,用户输入传递给邮件,但我无法在那里创建表。到目前为止,我所做的是:
HTML
<input type="text" class="form-control fc" name="patient" id="Patient">
<input type="date" class="form-control fc" name = "date" id="Date">
<input type="text" class="form-control fc" name = "Assistant" id="Assistant">
PHP部分
if(isset($_POST['submit'])) {
$email_to = "xyz@gmail.com";
$email_subject = "Data";
$patient = $_POST['patient'];
$date = $_POST['date'];
$Assistant = $_POST['Assistant'];
$email_message ="<html><body>";
$email_message .= "<table><tr><td>Field Name : </td><td>Value</td></tr>";
$email_message .= "<tr><td>Patient Name : </td><td>".$patient."</td></tr>";
$email_message .= "<tr><td>Date:</td><td> ".$date."</td></tr>";
$email_message .= "<tr><td>Assistant:</td><td> ".$Assistant."</td></tr></table>";
$email_message .="</body></html>";
// create email headers
$headers = 'From: '.xyz@gmail.com."\r\n".
'Reply-To: '.xyz@gmail.com."\r\n" .
'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); ?>
答案 0 :(得分:0)
要发送html邮件,您必须设置标题:
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
答案 1 :(得分:0)
使用PHPMailer https://github.com/PHPMailer/PHPMailer。
$mailer = new PHPMailer();
$mailer->isHTML(TRUE);
$mailer->Host = 'smtp host';
$mailer->Port = 'smtp post';
....
$mailer->body = "put your html here"
$mailer->send();