0

I'm setting up a website that has about 6 different HTML forms. I would like the data that people put into the form be sent to my gmail account. My web host is godaddy and I already had set up email forwarding with godaddy, but I haven't received them email when I uploaded the website files and tested the forms when the website was live.

I also changed the file extension from .html to .php to include the php code. However, in the end I didn't get an email. Additionally, I was reading about PHPMailer and Composer, but it seems all so complex, which shouldn't be if I set up email forwarding with godaddy for the gmail account.

NB: I'm extremely new to PHP

HTML Code:

        <div class="container">
        <div class="formBx">
            <form>
                <h2>Door to Door Inquiry</h2>
                <div class="inputBox">
                    <input type="text" name="name" required="required">
                    <span>Full Name</span>
                </div>
                <div class="inputBox">
                    <input type="text" name="mail" required="required">
                    <span>Email Address</span>
                </div>
                <div class="inputBox">
                    <input type="text" name="phone" required="required">
                    <span>Phone Number</span>
                </div>
                <div class="inputBox">
                    <textarea type="text" name="message" required="required"></textarea>
                    <span>Type Your Message Here...</span>
                </div>
                <div class="inputBox">
                    <input type="submit" value="Send" name="">
                </div>
            </form>
        </div>
            <div class="imgBx">
               <img src="images/door-door-delivery-service_82574-7443.jpg" alt="Picture of yellow, cartoon SUV.">
            </div>
        </div>
    </section>

PHP Code:

    if(isset($_POST['submit'])) {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];

    $to = "sitenameinfo@sitename.com";
    $subject = "Site contact form";

    $header = "From: ".$email."\r\n";
    $header .= "Cc: ".$email."\n";
    $header .= "Reply-To : ".$email."\r\n";
    $header .= "Return-Path : ".$email."\r\n";
    $header .= "X-Mailer: PHP\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";

    if(mail($to, $subject, $message, $header))
    {
      echo "Mail Sent Successfully";
    }else{
      echo "Mail Not Sent";
    }

    }
    ?>
RojiE
  • 35
  • 5
  • Why your `CC` has different line neding than rest of headers? I suggest using PHPMailer. Also your `submit` button does not have name, so you do not pass first condition – Justinas Jul 23 '20 at 11:26
  • @Justinas, Hahaha I don't know how I missed giving it a name. But I will for sure just use PHPMailer. But, I do have another question. The fact that I changed all the form html files to PHP, was that correct? I wasn't sure if there was a specific way for me to link the PHP code to that specific HTML file – RojiE Jul 23 '20 at 11:51
  • Well, that is correct way to pass form values to PHP script – Justinas Jul 23 '20 at 12:20
  • The way you link the HTML form to the PHP script which should execute when the form is submitted is via the form' action attribute, which you didn't use in your code (meaning the form will try to submit to the same page it's already on) – ADyson Jul 23 '20 at 13:24

0 Answers0