0

I've developed a website for a client (that will be hosted on their private server) that includes an enrollment form. Users input their first name, last name, email, phone number, and zip code. They also use a radio button to select if they've used the product before, and can check a box to receive news about the product.

That info is supposed to be sent using SMTP to an email address they handle. They then process the registry internally. So all it needs to do is collect the information and send it in an email. For the SMTP configuration the client has provided me with an IP address, a Port number, and they have stated that there is no Username or Password and no Encryption.

I have tried to follow many different tutorials online but I am new to PHP and have not been able to make it work.

Here is the html for the form:

<form id="enrollmentForm" name="email-form-3" action="" method="post" class="eForm">
    <label for="nombre" class="labels">FIRST NAME</label>
    <input type="text" class="w-input" maxlength="256" name="fName" id="fName" required="">

    <label for="apellido" class="labels">LAST NAME</label>
    <input type="text" class="text-field w-input" maxlength="256" name="lName" id="lName" required="">

    <label for="email" class="labels">EMAIL</label>
    <input type="text" class="w-input" maxlength="256" name="email" id="email" required="">

    <label for="phone" class="labels">PHONE</label>
    <input type="text" class="text-field-2 w-input" maxlength="256" name="phone" id="phone" required="">

    <label for="zip" class="labels">ZIP CODE</label>
    <input type="text" class="w-input" maxlength="256" name="zip" id="zip" required="">

    <label class="labels check">HAVE YOU USED OUR PRODUCT BEFORE?</label>
    <label id="usedBeforeYes" class="w-radio">
    <input type="radio" name="usedBefore" id="si" value="si" data-name="usedBefore?" required="" class="w-form-formradioinput w-radio-input"><span class="labels w-form-label" for="si">YES</span></label>

    <label id="usedBeforeNo" class="w-radio">
    <input type="radio" name="usedBefore" id="no" value="no" data-name="usedBefore?" required="" class="w-form-formradioinput w-radio-input"><span class="labels w-form-label" for="no">NO</span></label>

    <label class="w-checkbox">
        <input type="checkbox" id="checkBox" name="checkBox" class="w-checkbox-input">
        <span class="checkbox-label-2 w-form-label" for="checkbox-6">Would you like to receive more information about our product?</span>
    </label>

    <input type="submit" name="submit" value="SUBMIT" data-wait="One moment..." class="button w-button">

</form>

This is the PHP I have been trying to use:

<?php

if (isset($_POST["submit"]))
{
    $message =  "Info:" . "\n\n\n"
    . "First Name: " . $_POST["fName"] . "\n"
    . "Last Name: " . $_POST["lName"] . "]n"
    . "Email: " . $_POST["email"] . "\n"
    . "Phone Number: " . $_POST["phone"] . "\n"
    . "Zip Code: " . $_POST["zip"] . "\n"
    . "Repeat Customer?: " . $_POST["usedBefore"] . "\n"
    . "Send news?: " . $_POST["checkBox"];
    $mailTo = "internalEmail@client.com";
    $subject = "Customer Registry";
        
    require 'class\PHPMailer.php';
    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    $mail->setFrom($mailTo, 'Registry');
    $mail->Username = '';
    $mail->Password = '';
    $mail->Host = 'ip address provided';
    $mail->Port = 'port provided';
    $mail->SMTPSecure = 'tls';
    $mail->From = $mailTo;
    $mail->AddAddress($mailTo, 'Registry');
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body = $message;
    $mail->Send();
    if ($mail->Send())
    {
        echo('Message sent successfully');
    }
    else
    {
        echo('Error while sending message');
    }
}
?>

Many thanks in advance!

  • 1
    (1) **they have stated that there is no Username or Password and no Encryption** - if this is true then it is an open-relay . Please ask them to immediately change it . (2) If there is no encryption, what is the reason you set $mail->SMTPSecure = 'tls'; ? – Ken Lee May 02 '22 at 03:10
  • [Form](https://www.caniemail.com/search/?s=form) did not support in all email clients. It is better to use simple HTML email with link to let user enter the form on the web page, not in email directly. – vee May 02 '22 at 04:23
  • @vee they are not trying to put a form _into_ an HTML email, they are trying to send an email with data from a form submission on a website. – CBroe May 02 '22 at 07:30
  • What do the PHP/webserver logs show? Have you [enabled `SMTPDebug`](https://stackoverflow.com/questions/2896280/debugging-php-mail-and-or-phpmailer) to get more info from what PHPMailer is doing? Have you tried just copying [the simple examle from the docs](https://github.com/PHPMailer/PHPMailer), or from other questions here SO ([example](https://stackoverflow.com/questions/5335273/how-can-i-send-an-email-using-php))? – Don't Panic May 02 '22 at 07:33

0 Answers0