-1

So I'm building a small website and i need to create a html form where the values would be sent to my client's email.

The form code:

<form id="contact-form" method="POST" action="form-to-email.php" role="form">
        <div class="messages"></div>
        <div class="controls">
                <div class="row">
                        <div class="col-md-6">
                                <div class="form-group">
                                        <label for="form_name">Name *</label>
                                        <input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your Name *" required="required" data-error="Firstname is required.">
                                        <div class="help-block with-errors"></div>
                                </div>
                        </div>
                        <div class="col-md-6">
                                <div class="form-group">
                                        <label for="form_email">Email *</label>
                                        <input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your Email *" required="required" data-error="Email is required.">
                                        <div class="help-block with-errors"></div>
                                </div>
                        </div>
                </div>
                <div class="row">
                        <div class="col-md-6">
                                <div class="form-group">
                                        <label for="form_social">Other Socials</label>
                                        <input id="form_social" type="text" name="other_socials" class="form-control">
                                        <div class="help-block with-errors"></div>
                                </div>
                        </div>
                        <div class="col-md-6">
                                <div class="form-group">
                                        <label for="form_need">Services</label>
                                        <select class="form-select" aria-label="Default select example" name="services">
                                                <option selected>Select a Service</option>
                                                <option value="Live2D Vtuber Rigging">Live2D Vtuber Rigging</option>
                                                <option value="Animation">Animation</option>
                                                <option value="Illustration">Illustration</option>
                                                <option value="Graphics">Graphics</option>
                                                <option value="Others">Others</option>
                                                <option value="General Enquiry">General Enquiry</option>
                                        </select>
                                </div>
                        </div>
                </div>
                <div class="row">
                        <div class="col-md-12">
                                <div class="form-group">
                                        <label for="form_message">Message *</label>
                                        <textarea id="form_message" name="message" class="form-control" placeholder="Message for me *" rows="4" required="required" data-error="Please, leave us a message."></textarea>
                                        <div class="help-block with-errors"></div>
                                </div>
                        </div>
                        <div class="col-md-12">
                                <input type="submit" class="btn btn-success btn-send" value="Send message">
                        </div>
                </div>
        </div>
</form>

I'm using basic HTML/JS and php.

I've tried this example but I have an error 405 which I assume from another answer is due to me using a localhost (using MAMP localhost).

Friend suggested using Google smtp but i'm totally lost as i'm a beginner to frontend, so i'm not sure where to start.

I did some resaerch and there was suggestion to use PHPmailer but i'm not even sure how to intergrate it with my code?

Any suggestions on where to start off?

Davide Madrisan
  • 1,969
  • 2
  • 14
  • 22
  • You can get the answer here. https://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server – Tuan Dao Sep 19 '21 at 14:33
  • Does this answer your question? [Send email using the GMail SMTP server from a PHP page](https://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page) – Tangentially Perpendicular Sep 19 '21 at 15:28

1 Answers1

0

In your php file write it-

<?php
    $userName = $_POST['name'];
    $userEmail = $_POST['email'];
    $otherSocials= $_POST['other_socials'];
    $services= $_POST['services'];

    $to = "info@email.com"; // Add your client email addresss
    $body = "";

    $body .= "Name: ".$userName. "\r\n";
    $body .= "Email: ".$userEmail. "\r\n";
    $body .= "Other Socials: ".$otherSocials. "\r\n";
    $body .= "Services: ".$services. "\r\n";

    if(mail($to,$messageSubject,$body)){
        echo "Email Sent Successfully!";
    } else{
        echo "Sorry, something went wrong";
    }
?>

that's it.

Siam Ahnaf
  • 402
  • 4
  • 14