我正在尝试使用php mail()
函数发送pdf附件。但我不知道如何做到这一点。表单中的消息字段是用户可以使用html编辑器编辑的。没有附件它工作正常。
这是我的代码
<?php
include("../connect.php");
include("../admin_auth.php"); ?>
<?php
if($_POST['submit'] == "Submit")
{
$sql = mysql_query("select email from users where username='admin'");
$row = mysql_fetch_array($sql);
$email = $row['email'];
$path = $row['path'];
$messageAlert = "Email send successfully!!";
$to = $_POST['email'];
$from = $email;
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
if($_POST['type'] == 2)
{
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
}
mail($to, $_POST['subject'], $_POST['message'], $headers);
}
$message .= "";
$content =$messageAlert.'<br>
<form method="post" action="" enctype="multipart/form-data">
<table>
<tr>
<td>Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="subject" /></td>
</tr>
<tr>
<td>Message:</td>
<td>
<div class="w-box" id="n_wysiwg">
<div class="w-box-header">
<h4>WYSIWG Editor</h4>
</div>
<div class="w-box-content cnt_no_pad">
<textarea name="message" id="wysiwg_editor" cols="30" rows="10">'.$message.'</textarea>
</div>
</div>
</td>
</tr>
<tr><td>Attachment</td>
<td><input type="file" name="attachment" value="netelity.png"></td>
</tr>
<tr>
<td>Email Type</td>
<td><select name="type">
<option value="1">Plain</option>
<option value="2">HTML</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
';
$pre = 1;
include("html.inc");
附件将在$path
。我尝试关注THIS链接,但由于它使用$message
作为静态,因此在我的代码中,它必须来自用户输入,即$_POST['message']
,它不起作用。
实际上,当我打开此表单时,我希望自己附加附件。