Это мой PHP кодотправлять вложения и данные в форме по электронной почте с PHP
и мой HTML форма ниже, где я хочу, чтобы получить данные от имени, электронной почты, полей номера телефона и вложенного файла.
Теперь я попытался подключить файл (без ввода другой информации) в живой серверной среде. Я также получаю и прикрепляю его по почте в виде другого формата (например, я отправляю слово doc, но файл слова находится в формате dat, который не отображает данные в файле Word)
<?php
if(isset($_POST['submit']))
{
//The form has been submitted, prep a nice thank you message
$output = '<h1>Thanks for your file and message!</h1>';
//Set the form flag to no display (cheap way!)
$flags = 'style="display:none;"';
//Deal with the email
$to = '[email protected]';
$subject = 'Details and file attachments ';
$message = strip_tags($_POST['message']);
$attachment = (file_get_contents($_FILES['file']['tmp_name']));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: [email protected]\r\nReply-To: [email protected]";
$headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $message, $headers);
}
?>
Это мой HTML-файл предложить мне, как изменить код для получения значения другого поля, а также по электронной почте
<td height="12"> <?php echo $output; ?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" <?php echo $flags;?>>
<fieldset>
<legend>Submit your interest</legend>
<p><label class="title" for="name">Your name:</label>
<input type="text" name="name" id="name"><br /></p>
<p> <label class="title" for="email">Your email:</label>
<input type="text" name="email" id="email"></p>
<p> <label class="title" for="phone">Your phone:</label>
<input type="number" name="phone" id="phone"></p>
<p><label for="location" class="title">Total Experience :</label>
<select name="location" id="location">
<option value="ny">1</option>
<option value="il">2</option>
<option value="ca">3+</option>
</select></p>
<span class="title">Upload your resume</span>
<input type="file" name="resume" />
</p>
</fieldset>
<div><input type="submit" name="submit" id="submit" value="send"></div>
</form></td>
Не создавайте свои собственные электронные письма. Используйте phpmailer или swiftmailer. Тем более, что вы заполняете содержимое RAW файла в электронном письме, но заявляете, что оно закодировано в base64 ... –