A
Anonymous
Guest
Hello - First off I'm in no way a PHP developer, but I'm stepping through the process of learning how to build my own website. Part of the website is my contact page which has a basic form that someone fills out with name, subject, email, and message details. Once the form is submitted, the plan is for it to be emailed to me via GoDaddy's SMTP server (email account setup through cPanel). I've read many posts and watched several YouTube videos that seemed to be what I was looking for, but I've had no luck thus far. I even reached out to GoDaddy support who were no help whatsoever. I hope it is ok to show my code here.
My HTML Code:
My PHP Code:
My HTML Code:
Code:
<form class="form js-form-validate" action="php/mail.php" method="POST" data-aos="fade">
<div class="form__title">Drop Me A Line</div>
<div class="form__subtitle">Ask away! I'll try to respond within 24 hours</div>
<div class="form__group">
<div class="form__item">
<label class="form__field field">
<input type="text" name="full-name" placeholder="Full Name">
<span class="field__hint">Full Name</span>
<span class="underline"></span>
</label>
<div class="field-error" style="display: none"></div>
</div>
<div class="form__item">
<label class="form__field field">
<input type="email" name="email" placeholder="Email Address *" required>
<span class="field__hint">Email Address <span class="red">*</span>
</span>
<span class="underline"></span>
</label>
<div class="field-error" style="display: none"></div>
</div>
<div class="form__item">
<label class="form__field field">
<input type="text" name="subject" placeholder="Subject">
<span class="field__hint">Subject</span>
<span class="underline"></span>
</label>
<div class="field-error" style="display: none"></div>
</div>
</div>
<label class="form__field form__field--width-full field">
<textarea name="message" placeholder="Your message here"></textarea>
<span class="field__hint">Your message here</span>
<span class="underline"></span>
</label>
<div class="field-error" style="display: none"></div>
<button class="form__submit" type="submit">Send Message</button>
</form>
My PHP Code:
Code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require '../js/mailer/Exception.php';
require '../js/mailer/PHPMailer.php';
require '../js/mailer/SMTP.php';
$name = $_POST['full-name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
try {
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true;
$mail->Host = '[p3plzcpnl459192.prod.phx3.secureserver.net](https://l.facebook.com/l.php?u=http%3A%2F%2Fp3plzcpnl459192.prod.phx3.secureserver.net%2F%3Ffbclid%3DIwAR3aXzprlEtWfE-oTh8u3iT4stphGS2m-wpWB1o3nuEdPm1HAwwTQY1G-k4&h=AT09NlvPFvX4VJfw4ccKphYhZILdTT5XaT8fcImQVvEM2J1xtO7pVFIbEPLo9ds-0l8jgecYyvMfO1m7te10M8IOfUFk5gEHIBqbQ1q-ZH_nX7jYoe7SX1fxk4VgIl4XAw&__tn__=-UK-R&c[0]=AT3aEAkgUXCtWQJ7frkyCGBMMP3-uSvrHSFeQxjUAqbGt9vWLKUQv1KpKoKp2YewMBPb8mjSIWcIqCgl2k1M49RXDg6LPP6F5kMiYSzoW-mJrIGpmwkfdqrKwqDHbC-cK5NaTe0a-w4TxpZMlXv4jkGCQ9sX)';
$mail->Username = 'email address created in cPanel';
$mail->Password = 'mypassword';
$mail->SMTPOptions = array(
'tls' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Port = 587;
$mail->setFrom('address1', 'To Me');
$mail->addAddress('address2', 'Email address in which the contact form submission will be sent to');
$mail->isHTML(true);
$mail->Subject = 'Message from Liarch';
$mail->Body = 'Client name - ' . $name . '<br>' . 'Email - ' . $email . '<br>' . 'Subject - ' . $subject . '<br>' . 'Message - ' . $message;
$mail->send();
} catch (Exception $e) {
echo $mail->ErrorInfo;
}
?>