GoDaddy - PHPMailer

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:

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;

}

?>
 
Based on the code you provided, it looks like you're using the PHPMailer library to send the email on form submission. However, the code has some issues that may not work as expected. Here are some suggestions to help troubleshoot the issue.


1. Check the PHPMailer library path.
Make sure the path to the PHPMailer library files is correct. The code you provided uses relative paths ("../js/mailer/Exception.php", "../js/mailer/PHPMailer.php", "../js/mailer/SMTP.php"). I'm here. . Make sure these paths point exactly to the location of the PHPMailer library files on your server.

2. Check the SMTP host and port.
Double-check the SMTP host and port values you are using. The specified SMTP host value is "[p3plzcpnl459192.prod.phx3.secureserver.net](https:
//l.facebook.com/l.php?u=http://p3plzcpnl459192.prod.phx3.se...nuEdPm1HAwwTQY1G-k4&h=AT09NlvPFvX4VJfw4ccKphY hZIL dTT5XaT8fcImQVvEM2J1xtO7pVFIbEPLo9ds-0l8jgecYyvMfO1m7te10M8IOfUFk5geEHIBqbQ1q-ZH_nX7jYoe7SX1fxk4VgIl4XAw&__tn__=-UK-R&c [ 0] = AT3aEAkgUXCtWQJ7frkyCGBMMP3-uSvrHSFeQxjUAqbGt9vWLKUQv1KpKoKp2YewMBPb8mjSIWcIqCgl2k1M49RXDg6LPP6F5kMiYSzoW-mJrIGpmwkfdqrKwqDHbC-cK5NaTe0a-w4Txp ZM lXv4jkGCQ9sX)". Make sure this is the correct SMTP server hostname for your GoDaddy account. Also make sure that the SMTP port 587 is correct for GoDaddy's SMTP server.

3. Check SMTP authentication.
Make sure the email address and password specified for SMTP authentication are correct. The username should be the email address you created in cPanel and the password should be the proper password for that email account.

Four. Check for error messages.
To catch any exceptions that may occur during the email-sending process, enclose the code block within a "try" block with a catch statement. You can then issue an error message to identify the problem.


''''php
attempt {
// ...existing code...

$mail->send();
echo 'Email sent successfully;
} catch (exception $e) {
echo 'Unable to send an email. error:
', $mail->ErrorInfo;
}
""

Adding this catch block will allow you to check if PHPMailer is reporting any errors that may reveal why the email is not being sent.

Five. Debugging and logging:
If you continue to have problems, enable debug mode in PHPMailer to get more information about the email-sending process. To do this, add "$mail->SMTPDebug=SMTP".
:
debug_server;
 
Back
Top