I want to make contact form work/How Do I make php work on a website ?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
tornikee66
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Apr 21, 2018 5:03 am

Sat Apr 21, 2018 5:22 am

Hello!
Im a beginner just registered here. I know a little bit of css/html/javascript, have 0 understanding in using php on a website, nevertheless I understand what it is for and that it works with the server mails and databases.
Made a website not a long ago. created contact form which looks like this:
"<div class="container">

<div class="login">
<input type="text" placeholder="name" class="input">
<input type="text" placeholder="e-mail" class="input">
</div>

<div class="subject">
<input type="text" placeholder="Subject" class="input">
</div>

<div class="msg">
<textarea class="area" placeholder="Your Text"></textarea>
</div>

<div class="btni">Send</div> // this is a send button
</div>"
I urgently want to make this form send input text to Gmail mail, but don't know how. Nor I know how I make the php code work on a webpage, as it doesn't go in index.html and if I have something.php file I have no idea how I make a reference. I have no working php code for this contact form to send mails to Gmail. I looked up on youtube on other forums, asked my webdevelopment-knowing friends they dont know as non of them works with php.
I'm asking for help if you have very little time and give me directions on this. Please Please Please! I really need help here.
I uploaded the files on the free hosting of 0fees.us it all works, only php code for sending mails is missing.

chorn
php-forum Fan User
php-forum Fan User
Posts: 562
Joined: Fri Apr 01, 2016 2:18 am

Sat Apr 21, 2018 11:12 am

Lookup PHPMailer on github, it's an easy wrapper with many examples.

tornikee66
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Apr 21, 2018 5:03 am

Tue May 15, 2018 4:51 am

Thanks a lot I tried it out. with only php mailer it worked, it sent message through Gmail SMTP with 0 problem. but when I link it with HTML it gives me error : (
here is the code, it gives me error ""Message could not be sent. Mailer Error: Invalid address: (to):"
Any ideas? : (
html--->
<form method="post" action="send.php">
<div class="login">
<input type="text" name="name" placeholder="სახელი" class="input">
<input name="email" type="email" placeholder="e-mail მისამართი" class="input">
</div>
<!-- <div class="subject">
<input name="satauri" type="text" placeholder="სათაური" class="input">
</div> -->
<div class="msg">
<textarea name="message" class="area" placeholder="ტექსტი..."></textarea>
</div>
<div class="btni"><button class="btni1">გაგზავნა</button> </div>
</div>
</form


php ---->
<?php
$name = $_POST['name'];
$maili = $_POST['email'];
$message = $_POST['message'];



// Import PHPMailer classes into the global namespace
// These must be at the top of your scr1pt, not inside a functi0n
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '******@gmail.com'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to

//Recipients
$mail->setFrom('******@gmail.com','gmail');
$mail->addAddress($maili,$name); // Add a recipient
// Name is optional

$body="Hello ".$name."meili:".$message.'reply '.$maili;

//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Inquiry'.$name;
$mail->Body = $body;
$mail->AltBody = strip_tags($body);

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

chorn
php-forum Fan User
php-forum Fan User
Posts: 562
Joined: Fri Apr 01, 2016 2:18 am

Tue May 15, 2018 5:47 am

have a look at var_dump($_POST) to see what you get from the form.

Respocert
New php-forum User
New php-forum User
Posts: 3
Joined: Mon May 07, 2018 12:36 pm
Contact:

Tue May 15, 2018 11:42 pm

here is a blog post on designing forms with best practices, checkout here

Post Reply