Bar2012 Posted July 2, 2023 Share Posted July 2, 2023 Hi All - I designed a webpage hosted by GoDaddy and cannot get the php contact form to work correctly. I am using the following php script: <?php //Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; require_once 'vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'localhost'; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'myemailaddress'; // SMTP username $mail->Password = 'mypassword'; // SMTP password $mail->SMTPAutoTLS = false; $mail->Port = 25; //SMTP port //Recipients $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('recipient1@example.net', 'Joe User'); // Add a recipient $mail->addAddress('recipient2@example.com'); // Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); // Content if (isset($_POST['contact'])) { $name = $_POST['username']; $email = $_POST['useremail']; $subject = $_POST['subject']; $usermessage = $_POST['message']; $message ="Name = ". $name . "\r\n Email = " . $email . "\r\n Subject = " . $subject . "\r\n Message =" . $usermessage; // Attachments $mail->send(); if (!$mail->send()) { echo 'Email not sent an error was encountered: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } } ...along with the following html code: <form class="p-5 bg-white" action="contact.php" method="POST" enctype="multipart/form-data" onsubmit="return validateContactForm()"> <div class="margin-t-50"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label for="username">Name </label> <input type="text" class="form-control" id="username" placeholder="Your Name" required name="name" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="useremail">Email address </label> <input type="email" class="form-control" id="useremail" placeholder="Your Email" required name="email" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="subject">Subject </label> <input type="text" class="form-control" id="subject" placeholder="Your Subject.." required name="subject" /> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label for="message">Message </label> <textarea class="form-control" rows="5" id="message" placeholder="Your Message...." required name="message" /></textarea> </div> </div> </div> <div class="row"> <div class="col-sm-12 text-left"> <div class="custom-file-upload"> <!--<label for="file">File: </label>--> <input type="file" id="formFile" name="file" /> <span class="file-type-restrction">Upload only PDF or DOC file</span> </div> </div> <div class="col-sm-12 text-right"> <input type="submit" value="Submit" name="contact" class="btn btn-primary btn-md text-white"> </div> </div> </div> <div id="statusMessage"> <?php if (! empty($message)) { ?> <p class='<?php echo $type; ?>Message'><?php echo $message; ?></p> <?php } ?> </form> I appreciate any recommendations or thoughts. I previously contacted Godaddy, and the tech support was unable to assist, other than by providing the port address. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/317040-contact-form-issue-with-godaddy-phpmailer/ Share on other sites More sharing options...
gizmola Posted July 2, 2023 Share Posted July 2, 2023 You need to define what "not working correctly" means. $mail->Host = 'localhost'; This tries to send mail through your server. That is not going to work. With godaddy, you need to send your email through their mail servers. Typically they provide that information to you in some fashion. Quote Link to comment https://forums.phpfreaks.com/topic/317040-contact-form-issue-with-godaddy-phpmailer/#findComment-1610217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.