Время, использующее GitHub PHPMailer, и у меня есть проблема с отправкой писем. Данные, кажется, отправляются в форму, и я теряюсь за ее пределами.PHP Contact Form (PHPMailer)
Я знаю, что не использую ошибки на моей странице, поэтому на данный момент я печатаю их в php-форме.
HTML (index.php)
<form name="contactform" id="myform" class="fs-form fs-form-full" autocomplete="off" method="post" action="send.php">
<ol class="fs-fields">
<li>
<label class="fs-field-label fs-anim-upper" for="q1">What's your name?</label>
<input class="fs-anim-lower" id="q1" name="q1" type="text" placeholder="Johnny Bravo" required/>
</li>
<li>
<label class="fs-field-label fs-anim-upper" for="q2" data-info="We won't send you spam, we promise...">What's your email address?</label>
<input class="fs-anim-lower" id="q2" name="q2" type="email" placeholder="[email protected]" required/>
</li>
<li data-input-trigger>
<label class="fs-field-label fs-anim-upper" for="q3" data-info="This will help us know what kind of service you need">What can we do for you? <span style="font-size:20px;">(select one)</span></label>
<div class="fs-radio-group fs-radio-custom clearfix fs-anim-lower">
<span><input id="q3b" name="q3" type="radio" value="graphic"/><label for="q3b" class="radio-graphic">Graphic Design</label></span>
<span><input id="q3c" name="q3" type="radio" value="web"/><label for="q3c" class="radio-web">Web Design</label></span>
<span><input id="q3a" name="q3" type="radio" value="motion"/><label for="q3a" class="radio-motion">Motion Graphics</label></span>
<span><input id="q3d" name="q3" type="radio" value="other"/><label for="q3d" class="radio-other">Other/More</label></span>
</div>
</li>
<li>
<label class="fs-field-label fs-anim-upper" for="q4">Describe your project in detail.</label>
<textarea class="fs-anim-lower" id="q4" name="q4" placeholder="Describe here"></textarea>
</li>
<li>
<label class="fs-field-label fs-anim-upper" for="q5">What's your budget? (USD)</label>
<input class="fs-mark fs-anim-lower" id="q5" name="q5" type="number" placeholder="1000" step="100" min="100"/>
</li>
</ol><!-- /fs-fields -->
<button class="fs-submit" type="submit" value="Send">Send It</button>
</form><!-- /fs-form -->
PHP (send.php)
<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php';
$errors = [];
if(isset($_POST['q1'], $_POST['q2'], $_POST['message'])) {
$fields = [
'q1' => $_POST['q1'],
'q2' => $_POST['q2'],
'q3' => $_POST['q3'],
'q4' => $_POST['q4'],
'q5' => $_POST['q5']
];
foreach($fields as $field => $data) {
if(empty($data)) {
$errors[] = 'The ' . $field . ' field is required.';
}
}
if(empty($errors)) {
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->Host = 'smtp.gmail.com';
$m->Username = '[email protected]';
$m->Password = 'mypassword';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->isHTML();
$m->Subject = 'Contact form submitted';
$m->Body = 'From: ' . $fields['q1'] . ' (' . $fields['q2'] . ')<p>Budget</p><p>' . $fields['q5'] . '</p><p>Service</p><p>' . $fields['q3'] . '</p><p>Details</p><p>' . $fields['q4'] . '</p>';
$m->FromName = 'Contact';
$m->AddAddress('[email protected]', 'Ollie Taylor');
if($m->send()) {
header('Location: thanks.php');
die();
} else {
$errors[] = 'Sorry, could not send email. Try again later.';
}
}
} else {
$errors[] = 'Something went wrong.';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('Location: index.php');
Thankyou!
Спасибо, 1-й и 2-й были только правки, сделанные до публикации, чтобы защитить учетные данные моего сервера. Зафиксирует третью и отчитается. Спасибо! –
Нет, исправлена и обновлена вышеуказанный раздел кода и по-прежнему нет исправления. Попробовали как Google SMTP, так и мои собственные, не повезло. –