PHP邮件程序,如何插入HTML表
我有PHP mailer脚本,我正试图将HTML表添加到其中,但当我这样做时,脚本停止工作 下面是PHP邮件程序脚本PHP邮件程序,如何插入HTML表,php,html,phpmailer,Php,Html,Phpmailer,我有PHP mailer脚本,我正试图将HTML表添加到其中,但当我这样做时,脚本停止工作 下面是PHP邮件程序脚本 <?php // Insert your email/web addresses and correct paths $mailto = 'adil@*******.co.uk' ; $from = "web@city.com" ; $subject = "Query from ******* 2012"; $headers = "From: ******* Website
<?php
// Insert your email/web addresses and correct paths
$mailto = 'adil@*******.co.uk' ;
$from = "web@city.com" ;
$subject = "Query from ******* 2012";
$headers = "From: ******* Website";
$formurl = "http://*******.co.uk/citycoaches3/formmail.php" ;
$errorurl = "http://*******.co.uk/citycoaches3/error.php" ;
$thankyouurl = "http://*******.co.uk/citycoaches3/thankyou.php" ;
// Place Your Form info here...
$pickuppoint = ($_POST['pickuppoint']);
$destination = ($_POST['destination']);
// Check If Empty
// Add more Validation/Cleaning here...
// Place your Corresponding info here...
$message =
"Pick Point: $pickuppoint\n\n" .
"Destination: $destination\n\n" .
"noppl: $noppl\n\n"
;
// Leave Alone
mail($mailto, $from, $message);
header( "Location: $thankyouurl" );
exit ;
?>
在此方面的任何帮助都将不胜感激
这是我试过的
<?php
$fromAddr = 'adil@********.co.uk'; // the address to show in From field.
$recipientAddr = 'quotes@********.co.uk';
$subjectStr = '[Quick] Query From ********';
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$forward = 1;
$formurl = "http://www.********.co.uk/formmail.php" ;
$errorurl = "http://www.********.co.uk/error.php" ;
$thankyouurl = "http://www.********.co.uk/thankyou.php" ;
header("location:thankyou.php");
$mailBodyText = <<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Thank You</title>
</head>
<body>
<img src="http://********.co.uk/images/mailsig.png" /> \n\n<br />
<span style="color:#900; font-size:18px;">Below is the result submitted from <strong>[Quick Quote] ******** Website</strong>. It was submitted on <strong>$date at $time</strong>.\n\n</span>
<p><table width="600" border="1" cellpadding="5px">
<tr>
<td><b>Pickup Date:</b> </td>
<td>{$_POST['date']}<br></td>
</tr>
<tr>
<td><b>Pickup Time:</b> </td>
<td>{$_POST['PickupTime-Hours']}:{$_POST['PickupTime-Mins']}<br></td>
</tr>
<tr>
<td><b>Pickup Point:</b> </td>
<td>{$_POST['PickUp-Point']}<br></td>
</tr>
<tr>
<td><b>Destination:</b> </td>
<td>{$_POST['Destination']}<br></td></tr>
<tr>
<td><b>No. Of People:</b> </td>
<td>{$_POST['No-of-Persons']}<br></td>
</tr>
<tr>
<td><b>Journey Type:</b> </td>
<td>{$_POST['JourneyType']}<br></td>
</tr>
<tr>
<tr>
<td><b>Return Date:</b> </td>
<td>{$_POST['returnDate']}<br></td>
</tr>
<tr>
<td><b>Return Time:</b> </td>
<td>{$_POST['returnTime-Hours']}{$_POST['returnTime-Mins']}<br></td>
</tr>
<tr>
<tr>
<td><b>Vehicle Type:</b> </td>
<td>{$_POST['type']}<br></td>
</tr>
<tr>
<tr>
<td><b>Full Name:</b> </td>
<td>{$_POST['Full-Name']}<br></td>
</tr>
<tr>
<tr>
<td><b>Tel / Mobile:</b> </td>
<td>{$_POST['Tel-Mobile']}<br></td>
</tr>
<tr>
<td><b>Email:</b> </td>
<td>{$_POST['Email']}<br></td>
</tr>
<tr>
</table>
</p>
</body>
</html>
HHHHHHHHHHHHHH;
$headers= <<<TTTTTTTTTTTT
From: $fromAddr
MIME-Version: 1.0
Content-Type: text/html;
TTTTTTTTTTTT;
mail($mailto, $from, $message,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
header( "Location: $thankyouurl" );
exit ;
?>
由于某种原因,仍然不起作用
更新如下:
移除后
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
“发件人:\“$name\”$头巾。答复:\“$name\”。
我设法收到了电子邮件,但它粘贴了$message中的全部代码。在电子邮件正文部分使用并插入表格尝试从文件中获取HTML:
$message = file_get_contents('./path/email.html') // it's easyer to maintain but not mandatory
并添加一个html内容类型标题
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
然后
如果您想在发送给收件人的邮件中显示messagebody,可能应该尝试在代码中添加引号:
$mailBodyText = "<<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Thank You</title>
</head>
<body>
<img src="http://********.co.uk/images/mailsig.png" /> \n\n<br />
<span style="color:#900; font-size:18px;">Below is the result submitted from <strong> [Quick Quote] ******** Website</strong>. It was submitted on <strong>$date at $time</strong>.\n\n</span>
<p><table width="600" border="1" cellpadding="5px">
<tr>
<td><b>Pickup Date:</b> </td>
<td>{$_POST['date']}<br></td>
</tr>
<tr>
<td><b>Pickup Time:</b> </td>
<td>{$_POST['PickupTime-Hours']}:{$_POST['PickupTime-Mins']}<br></td>
</tr>
<tr>
<td><b>Pickup Point:</b> </td>
<td>{$_POST['PickUp-Point']}<br></td>
</tr>
<tr>
<td><b>Destination:</b> </td>
<td>{$_POST['Destination']}<br></td></tr>
<tr>
<td><b>No. Of People:</b> </td>
<td>{$_POST['No-of-Persons']}<br></td>
</tr>
<tr>
<td><b>Journey Type:</b> </td>
<td>{$_POST['JourneyType']}<br></td>
</tr>
<tr>
<tr>
<td><b>Return Date:</b> </td>
<td>{$_POST['returnDate']}<br></td>
</tr>
<tr>
<td><b>Return Time:</b> </td>
<td>{$_POST['returnTime-Hours']}{$_POST['returnTime-Mins']}<br></td>
</tr>
<tr>
<tr>
<td><b>Vehicle Type:</b> </td>
<td>{$_POST['type']}<br></td>
</tr>
<tr>
<tr>
<td><b>Full Name:</b> </td>
<td>{$_POST['Full-Name']}<br></td>
</tr>
<tr>
<tr>
<td><b>Tel / Mobile:</b> </td>
<td>{$_POST['Tel-Mobile']}<br></td>
</tr>
<tr>
<td><b>Email:</b> </td>
<td>{$_POST['Email']}<br></td>
</tr>
<tr>
</table>";
$mailBodyText=“因为我认为其他答案还没有给你正确的方向,这里是我的补充:
$name = _("test"); // Or insert variable
$message = <<<EOF
// html here
<p>hello $name</p>
EOF;
$to = "";
$subject = "";
// 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";
// Additional headers
$headers .= 'From: Example <info@example.com>' . "\r\n";
// Mail it
mail($to, $subject, $email, $headers);
$name=u(“test”);//或插入变量
$message=非常感谢您的帮助和建议
我终于在这里工作了,我就是这么做的
在插入的$message中:
$message = "<html><body>
<b><FONT COLOR='#900' SIZE='13px'>Hi this is working now</FONT></b>
<table width='400' border='0' cellpadding='5px'>
<tr>
<td><b><FONT COLOR='#900'>Pickup Date:</FONT></b> </td>
<td>{$_POST['date']}<br></td>
</tr>
</table>
</html></body>";
一切正常,再次感谢大家!请在您尝试的时候将代码与表格一起显示。这是我尝试过但似乎不起作用的示例的可能重复。我以前使用过PHP HTML emailer,但我现在使用的是教程。当我在$message中插入HTML标记时,脚本停止工作。好的,所以最初的问题不完整。您是否收到任何错误?请尝试错误报告(E_ALL)如果您收到的是空白页而不是错误,请在上显示错误我为没有在开始时提供所有信息表示歉意。我已更新了问题,删除了几个标题后发送电子邮件,但它在电子邮件中发布了全部代码。这意味着标题有问题,它在电子邮件标题中获取的是文本而不是html。您使用$headersr定义html电子邮件,但在邮件功能中,我找不到$headers。您使用的是$headersep而不是$headers。请检查它。检查了所有的标题并将$headersep更改为$headers。仍然无法工作。我将尝试此操作。感谢您的帮助请在双引号内将双引号更改为单引号:)请再次检查代码,您将继续在一个完全错误的方向…使用
$message = "<html><body>
<b><FONT COLOR='#900' SIZE='13px'>Hi this is working now</FONT></b>
<table width='400' border='0' cellpadding='5px'>
<tr>
<td><b><FONT COLOR='#900'>Pickup Date:</FONT></b> </td>
<td>{$_POST['date']}<br></td>
</tr>
</table>
</html></body>";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";