-1

I'm a little bit new with with php and i just want to ask how can i make the the "Send Message" button send the inputted information on the form i created to my email.

Here's the code:

    <section id="three">
    <h2>Email Me!</h2>
    <p>You will receive a reply within 24-48 hours.</p>
    <div class="row">
        <div class="8u 12u$(small)">
            <form method="post" action="MAILTO:sample@email.com">
                <div class="row uniform 50%">
                    <div class="6u 12u$(xsmall)"><input type="text" name="name" id="name" placeholder="Name" /></div>
                    <div class="6u$ 12u$(xsmall)"><input type="email" name="email" id="email" placeholder="Email" /></div>
                    <div class="12u$"><textarea name="message" id="message" placeholder="Message" rows="4"></textarea></div>
                </div>
            </form>
            <ul class="actions">
                <li><input type="submit" value="Send Message" /></li>
            </ul>
        </div>
        <div class="4u$ 12u$(small)">
            <ul class="labeled-icons">
                <li>
                    <h3 class="icon fa-home"><span class="label">Address</span></h3>
                    1234 Somewhere Rd.<br />
                    Nashville, TN 00000<br />
                    United States
                </li>
                <li>
                    <h3 class="icon fa-mobile"><span class="label">Phone</span></h3>
                    000-000-0000
                </li>
                <li>
                    <h3 class="icon fa-envelope-o"><span class="label">Email</span></h3>
                    <a href="#">hello@untitled.tld</a>
                </li>
            </ul>
        </div>
    </div>
</section>

Thanks!

user2910182
  • 31
  • 2
  • 13

3 Answers3

0

I'm not quite sure but email from php server almost all of them ends up in spam folder (trust issues by mail provider). But if you're interested, you can send mail via email function:

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

source: PHPDocs

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

What I recomend using is Mail sending servive like SendGdrid or MailChimp, those are easy to use and have pretty simpe API to work with. Free plan has a lot to offer, And you can send plain html through their api and it will be fine.

0
<?php
if(isset($_POST['submit'])) // on submit click no need to action of the form
{
$name = $_POST['name'];
$email = $_POST['email'];


$to = "somebody@example.com";
$subject = "My subject";
$body = "name:" . $name . "Email:" . $email;
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$body,$headers);
}
?>
Kishan Sanghani
  • 279
  • 3
  • 14
  • Hi what do you mean by on submit no need to action of the form, And mind if i ask where should i attach this php code on the html5 index or should i create a .php file for this? Thanks! – user2910182 Aug 13 '16 at 08:52
  • yes you need to create index.php file create this code top of the page – Kishan Sanghani Aug 13 '16 at 08:53
0

I would recommend using PHPMailer to send email from PHP. Here's the steps to accomplish this.

  1. Go to the Github repository.
  2. Download the ZIP.
  3. Extract it in your public_html directory.
  4. include '/path/to/PHPMailer/PHPMailerAutoload.php'; at the top of your PHP script.
  5. Get the values from the HTML form like you normally would.

Here's an example...

index.html

<form action="index.php" method="post">
    <input type="email" name="email">
    <input type="text" name="name">
    <input type="text" name="subject">
    <input type="text" name="message">
</form>

index.php

include '/path/to/PHPMailer/PHPMailerAutoload.php';

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

$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, "ssl" also accepted
$mail->Port = 587; // TCP port to connect to

$mail->setFrom('your email', 'your name'); // from
$mail->addAddress($email, $name); // to
$mail->isHTML(true); // if html

$mail->Subject = $subject;
$mail->Body = $message; //HTML

if($mail->send()){
    echo 'Mail sent!';
}
else {
    echo 'Mail failed!';
}
CloudBranch
  • 1,434
  • 3
  • 18
  • 23