您想将表单值作为附件而不是电子邮件的实际正文发送?如果是这样,您可以使用表单数据创建一个 html 页面并将其保存在您的服务器上。然后,发送。如果您需要帮助,请告诉我,我会发布一些代码。但是,我不太推荐这种方法。在我看来,您应该在电子邮件的正文中发送它。
创建文件:
$fh = fopen($filename, 'w') or die("can't open file");
fwrite($fh, '<html><body>');
fwrite($fh, "<h1>$title</h1>$text");
fwrite($fh, '</body></html>');
fclose($fh);
通过 php mailer 发送文件:
$mail->AddAttachment($whereEverYouSavedYourFile, $whatEverYourFileNameIs);
如果不起作用,请尝试并发布代码(可能是针对您的特定问题的新问题)。
编辑:
要发送带有帖子数据的电子邮件,请将表单提交到包含以下内容的 PHP 页面:
<?php
// get and sanitize post data like this
// note: you must have a form field with a 'name' of 'firstName' and on of 'lastName'
$firstName = htmlspecialchars($_POST['firstName'], ENT_QUOTES, 'UTF-8');
$lastName = htmlspecialchars($_POST['lastName'], ENT_QUOTES, 'UTF-8');
// put the data in a new variable
$body = <<<HTML
First name: $firstName \r\n
Last name: $lastName \r\n
HTML;
// send mail
mail('whoEver@theirEmailAddress.com', 'form data', $body);
?>