Prince Joal
Web Developer
  • Name: Prince

  • Birthday: 28 February 1993

  • Job: Freelancer

  • Email: i@princejoal.com

  • Skype: 1081a1d198d8081c

free-smtp

A website is incomplete without mail functionality Both static and dynamic websites require it. As contact form or another way like feedback form or anyway, you can use it, So today I will tell you how you can send email from the website in an easy way.

With Few steps, you can, integrate this PHP code with your website and receive your website data or form it into your email helping Gmail SMTP. You need to change  $mail->Username = 'mail@gmail.com';  mail id here and password $mail->Password = '#########';  here

 

Before Using this you need to change some settings in your Gmail account so that you can use Gmail SMTP – [How To Enable Less Secure App]

1. Turning on ‘less secure apps’ settings as mail domain Administrator

  1. Open your Google Admin console (admin.google.com).
  2. Click Security > Basic settings.
  3. Under Less secure apps, select Go to settings for less secure apps.
  4. In the subwindow, select the Enforce access to less secure apps for all users radio button.
    (You can also use the Allow users to manage their access to less secure apps, but don’t forget to turn on the less secure apps option in users’ settings then!)
  5. Click the Save button.
less secure app access

2. Turning on ‘less secure apps’ settings as mailbox user

  1. Go to your (Google Account).
  2. On the left navigation panel, click Security.
  3. On the bottom of the page, in the Less secure app access panel, click Turn on access.
    If you don’t see this setting, your administrator might have turned off less secure app account access (check the instruction above).
  4. Click the Save button.

index.php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer’s autoloader
require ‘vendor/autoload.php’;
$mail = new PHPMailer(true);

$mail = new PHPMailer(true);

Need to configure

$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail@gmail.com'; // your email id
$mail->Password = '#########'; // your password
$mail->SMTPSecure = 'tls';
$mail->Port = 587; //587 is used for Outgoing Mail (SMTP) Server.
$mail->setFrom('mail@gmail.com', 'Prince Joal');
$mail->addAddress('i@princejoal.com'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML

$bodyContent = '<h1>HeY!,</h1>';
$bodyContent .= '<p>This is a email that Prince joal send you From LocalHost using PHPMailer</p>';
$mail->Subject = 'Email from PrinceJoal Web';

Download code

Tags: Php, Technology

4 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x