Fist time using the GitHub PHPMailer and I have an issue with sending emails.
The data seems to be sent to the form and I am lost beyond that.
I know I am not using the errors in my page, which is why for now I am printing them to the php form.
html (index.php)
[php]
-
What’s your name?
-
What’s your email address?
-
What can we do for you? (select one)
Graphic Design
Web Design
Motion Graphics
Other/More</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]
PHP (send.php)
[php]<?phpsession_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');[/php]
Thankyou!