Bravo List
Register
Go Back   > Bravo List > P2P > Forum > Tutorials
Reply
  #1  
Old 25th May 2022, 12:22
BamBam0077 BamBam0077 is offline
Banned
 
Join Date: Jul 2013
P2P
Posts: 410
Wink Create A PHP Send Email Contact Form - Using PHPMailer - Step By
Create A PHP Send Email Contact Form - Using PHPMailer - Step By Step


[VIDEO]https://m.youtube.com/watch?v=DKq1n-awLcw[/VIDEO]

Description

Hello everyone! In this video, you are going to learn step by step how to create a contact form to send an email to a specific email address using PHPMailer.


There is a web page on a website that allows users to make contact with the site owner called the contact page. The page has fields for filling in email, name, message and etc. On most websites, email and mail addresses are also included as more info. however, the contact form provides major space, convenient way for users to communicate with the site owner for this purposes.


Lets see how to do it according to this tutorial. First yo need to download the PHP mailer from github. Then extract that file and copy the file to the folder that you created in htdocs. Watch the video for more details. Then you have to do a important step In your gmail account (the gmail account that you are going to use to send emails) go to your account settings and in the security tab you can see "less secure app access ". In default it is turned off and you need to turn it on. It's important. then start the apache server on your localhost. Then start to code. In the index.php file you need to create the contact form . The code the sendEmail.php file (follow the video). I think it is not hard to follow. Hope this video will be helpful to create a contact form to send emails using your gmail account.


You Might Also Like

Contact Page | With Sending EmailsCreate A Login And Logout SystemServer Side Ajax JQuery CRUD Data Table

All the source codes and source files and available to download from here. Use the download button or copy and paste the code from the text editors. My opinion is first try to do it by following the video line by line. It will help you t o understand all of it. After that, if your code is wrong or not working use the given source codes to compare with your code. It will help you to understand all of your mistakes.


Source Codes For Create a PHP Send Email Contact Form

Save As Index.php

<!DOCTYPE html>
<html>
<head>
<title>Send an Email</title>
</head>
<body>

<center>
<h4 class="sent-notification"></h4>

<form id="myForm">
<h2>Send an Email</h2>

<label>Name</label>
<input id="name" type="text" placeholder="Enter Name">
<br><br>

<label>Email</label>
<input id="email" type="text" placeholder="Enter Email">
<br><br>

<label>Subject</label>
<input id="subject" type="text" placeholder=" Enter Subject">
<br><br>

<p>Message</p>
<textarea id="body" rows="5" placeholder="Type Message"><textarea><!--textarea tag should be closed (In this coding UI textarea close tag cannot be used)-->
<br><br>

<button type="button" onclick="sendEmail()" value="Send An Email">Submit</button>
</form>
</center>

<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function sendEmail() {
var name = $("#name");
var email = $("#email");
var subject = $("#subject");
var body = $("#body");

if (isNotEmpty(name) && isNotEmpty(email) && isNotEmpty(subject) && isNotEmpty(body)) {
$.ajax({
url: 'sendEmail.php',
method: 'POST',
dataType: 'json',
data: {
name: name.val(),
email: email.val(),
subject: subject.val(),
body: body.val()
}, success: function (response) {
$('#myForm')[0].reset();
$('.sent-notification').text("Message Sent Successfully.");
}
});
}
}

function isNotEmpty(caller) {
if (caller.val() == "") {
caller.css('border', '1px solid red');
return false;
} else
caller.css('border', '');

return true;
}
</script>

</body>
</html>

And....,

Save As sendEmail.php

<?php
use PHPMailer\PHPMailer\PHPMailer;

if(isset($_POST['name']) && isset($_POST['email'])){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];

require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/SMTP.php";
require_once "PHPMailer/Exception.php";

$mail = new PHPMailer();

//smtp settings
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "youremail@gmail.com"; // !needs your attention look and edit
$mail->Password = 'yourpassword'; // !needs your attention look and edit
$mail->Port = 465;
$mail->SMTPSecure = "ssl";

//email settings
$mail->isHTML(true);
$mail->setFrom($email, $name);
$mail->addAddress("youremail@gmail.com"); // !needs your attention look and edit
$mail->Subject = ("$email ($subject)");
$mail->Body = $body;

if($mail->send()){
$status = "success";
$response = "Email is sent!";
}
else
{
$status = "failed";
$response = "Something is wrong: <br>" . $mail->ErrorInfo;
}

exit(json_encode(array("status" => $status, "response" => $response)));
}

?>

ADD-ON PHPMAILER

How to install phpmailer in linux

June 7, 2017 admin 0 Comments

PHPMailer - A full-featured email creation and transfer class for PHP. Probably its the world's most popular code for sending email from PHP. The only PHP function that supports this is the mail() function.

This article explains the steps to install phpmailer in linux server.



For Ubuntu servers,

Step1: Update the repositories

#apt-get update

Step2: Install phpmailer

#apt-get install libphp-phpmailer



For Centos servers,

Step1: Download the package

#wget https://github.com/PHPMailer/PHPMail...ive/master.zip

Step2: Extract the downloaded file

#unzip master

Step3: Move phpmailer files to the required folder

#mv PHPMailer-master /folder/



That's all.......

Credits -
Contact Us HTML - https://www.codingsnow.com/2021/01/c...tact-form.html
PHPMailer ~ https://techies-world.com/how-to-ins...iler-in-linux/

Last edited by BamBam0077; 25th May 2022 at 12:40.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 23:54. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.