-1

我有 PHP 邮件程序脚本,我正在尝试将 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";
$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>" .

我设法收到了这封电子邮件,但它粘贴了 $message 中的整个代码。

4

5 回答 5

0

尝试从文件中获取 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";

然后

mail($mailto, $from, $message, $headers) //notice the headers;
于 2013-11-15T10:28:46.063 回答
0

由于我认为其他答案还没有给你正确的方向,这是我的补充:

$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);

发送电子邮件时,您将需要 html 标头。

于 2013-11-15T10:54:31.300 回答
0

非常感谢您的帮助和建议。

我终于让它在这里工作就是我所做的。

在 $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>";

并添加了以下标题

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

所有工作再次感谢大家!

于 2013-11-15T18:38:05.883 回答
-1

使用php html 电子邮件并在电子邮件正文部分插入表格

于 2013-11-15T10:21:51.617 回答
-1

如果您想在消息中向收件人显示消息正文,也许您应该尝试在代码中加上引号:

$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>";
于 2013-11-15T10:47:37.913 回答