Код | <div class="mailinfo"><?php
function show_form()
{ ?>
<form action="" method="post" enctype="multipart/form-data"> <h3>Контактная информация</h3>
<label for="company" class="imp">Название компании:</label><br /> <input type="text" name="company" /><br />
<label for="fio" class="imp">Контакное лицо (Ф.И.О):</label><br /> <input type="text" name="fio" /><br />
<label for="tel" class="imp">Контактный телефон:</label><br /> <input type="text" name="tel" /><br />
<label for="mail">E-mail:</label><br /> <input type="text" name="mail" /><br />
<h3>Описание оборудования</h3>
<label for="name" class="imp">Наименование:</label><br /> <textarea name="name"></textarea><br />
<label for="producer">Производитель: </label><br /> <input type="text" name="producer" /><br />
<label for="country">Страна:</label><br /> <input type="text" name="country" /><br />
<label for="tnved">Код ТНВЭД: </label><br /> <input type="text" name="tnved" /><br />
<label for="descr">Примечания:</label><br /> <textarea name="descr"></textarea><br />
<h3>Документы, прилагаемые к запросу</h3>
<label for="attachfile">Приложить файл:</label><br /> <input name="attachfile" type="file" size="28" /><br />
<input value=" " type="submit" name="submit" class="btn" /> <br />
<label class="imp"></label>Поля, отмеченные красным, обязательны для заполнения </form></div> <? }
function complete_mail() { $_POST['company'] = substr(htmlspecialchars(trim($_POST['company'])), 0, 1000); $_POST['fio'] = substr(htmlspecialchars(trim($_POST['fio'])), 0, 1000); $_POST['tel'] = substr(htmlspecialchars(trim($_POST['tel'])), 0, 1000); $_POST['mail'] = substr(htmlspecialchars(trim($_POST['mail'])), 0, 1000); $_POST['name'] = substr(htmlspecialchars(trim($_POST['name'])), 0, 10000); $_POST['producer'] = substr(htmlspecialchars(trim($_POST['producer'])), 0, 1000); $_POST['country'] = substr(htmlspecialchars(trim($_POST['country'])), 0, 1000); $_POST['tnved'] = substr(htmlspecialchars(trim($_POST['tnved'])), 0, 1000); $_POST['descr'] = substr(htmlspecialchars(trim($_POST['descr'])), 0, 10000);
if (empty($_POST['company'])) output_err(0); if (empty($_POST['fio'])) output_err(2); if (empty($_POST['tel'])) output_err(3); if (!empty($_POST['mail'])){ if(!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $_POST['mail'])) output_err(1);} if (empty($_POST['name'])) output_err(4); $mess = ' <h3>Контакнтая информация</h3> <b>Название компании: </b>'.$_POST['company'].'<br /> <b>Контактное лицо (Ф.И.О.): </b>'.$_POST['fio'].'<br /> <b>Контактный телефон: '.$_POST['tel'].'<br /> <b>E-mail: </b>'.$_POST['mail'].'<br /> <h3>Описание оборудования</h3> <b>Наименование: </b>'.$_POST['name'].'<br /> <b>Производитель: </b>'.$_POST['producer'].'<br /> <b>Страна: </b>'.$_POST['country'].'<br /> <b>Код ТНВЭД: </b>'.$_POST['tnved'].'<br /> <b>Примечание: </b>'.$_POST['descr'];
require 'class.phpmailer.php'; $mail = new PHPMailer(); if(!empty($_POST['mail'])){ $mail->From = $_POST['mail']; } $mail->FromName = $_POST['company']; $mail->AddAddress($SETTINGS['mail'], 'Имя'); // Так не работает, выдает выше привиденную ошибку если напишу вместо $SETTINGS['mail'] мейл то все акей. распечатка $Settings['mail'] - выдает то что нужно. $mail->IsHTML(true); $mail->Subject = 'Запрос на поставку оборудования';
if(isset($_FILES['attachfile'])) { if($_FILES['attachfile']['error'] == 0){ $mail->AddAttachment($_FILES['attachfile']['tmp_name'], $_FILES['attachfile']['name']); } }
$mail->Body = $mess;
if (!$mail->Send()) die ('Mailer Error: '.$mail->ErrorInfo); echo 'Спасибо! Ваша заявка принята к рассмотрению.'; }
function output_err($num) { $err[0] = 'ОШИБКА! Не введено название компании.'; $err[1] = 'ОШИБКА! Неверно введен e-mail.'; $err[2] = 'ОШИБКА! Не введено Ф.И.О. отправителя.'; $err[3] = 'ОШИБКА! Не введен телефон.'; $err[4] = 'ОШИБКА! Не введено Наименование оборудования.'; echo '<p>'.$err[$num].'</p>'; show_form(); exit(); }
if (!empty($_POST['submit'])) complete_mail(); else show_form(); ?>
|
|