TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • PHP
  • How to Send an Email using PHP?[With Source Code]
PHP

How to Send an Email using PHP?[With Source Code]

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
0 1,505
Share

if you guyz are searching for the tutorial that shows how you can send email using PHP Script or validating email address in PHP, then you are in the right tutorial. So let’s start.

“This tutorial may be very useful for those who want to integrate email sending features in their project which is developed in PHP”.

For sending email using PHP: Mainly, you have to do two task:

  1. Downloading and Configurating Mail Routing Software
  2. Writing PHP Script to send an email

You need to download this software having the name sendmail click here and copy the file inside your localhost root folder in my case c://wamp64/sendmail and then open that sendmail and find sendmail.ini file and open this file with notepad and  then scroll down and find following term:

 

auth_username=
auth_password=
force_sender=
hostname=
smtp_server=
smtp_port=

Write your gmail in the place of auth_username, password to auth_password, again your gmail in force_sender, and localhost in hostname same as following:

auth_username=example@example.com //your gmail account
auth_password= ******* //your email password
force_sender=  example@example.com   //your gmail account
hostname=localhost
smtp_server=smtp.gmail.com
smtp_port=587

After completing this save that file.

Again open php.ini file from your server application. in case of wampserver, click the green icon of wamp server from system tray, hover over PHP and then choose php.ini file, open that file in notepad and find mail function. i.e. [mail function] inside this [mail function] find the following parameters:

SMTP=
smtp_port=
sendmail_from =
sendmail_path =

set the following value to them:

SMTP= smtp.gmail.com
smtp_port=587
sendmail_from =example@example.com // your gmail account
sendmail_path =”C:\wamp64\sendmail\sendmail.exe -t”

and save this php.ini file for more details you need to watch this video: CLICK HERE

Now write the following piece of code in any text editor software, i am using Dreamweaver CC and saved this php file in .php extension in your localhost and run (Note: your php file will not execute in the same way you run your html file, because PHP is server side scripting language so you need to have any server application to run this file.  watch this video to configure site and testing server in Dreamweaver CC: https://youtu.be/L4ex3S8BVCo or read here: click here)


<!doctype html>
<?php
if(isset($_POST['submit'])){
$to = $_POST['temail'];
if(!filter_var($to, FILTER_VALIDATE_EMAIL)){
echo("enter the correct email");}
else{
$from = $_POST['femail'];
if(!filter_var($from, FILTER_VALIDATE_EMAIL)){
echo("enter the correct email");
}else{
$fname= $_POST['fname'];
$lname = $_POST['lname'];
$message = $fname."".$lname."\n" .$_POST['message'];
$message=wordwrap($message, 70);
$hearder = "from".$from;
$subject = "from submission";
mail($to, $subject, $message, $hearder);
echo("email send");
}

}
}
//}
?>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="emailone.php" method="post">
<table align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="fname" placeholder="First Name">
<input type="text" name="lname" placeholder="Last name"></td><br><br>

</tr>
<tr>
<td>To:</td>
<td><input type="email" name ="temail" placeholder="example@example.com"</td>
</tr>
<tr>
<td>From:</td>
<td><input type="email" name ="femail" placeholder="example@example.com"</td>
</tr>
<tr>
<td>Message</td>
<td><textarea name="message" rows="5" cols="40" placeholder="enter your useful message here"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Send"</td>
</tr>
</table>
</form>
</body>
</html>

that’s it.

 

Watch the video:

Continue Reading
How do I send PHP mail via SMTPhow to send email from php script using smtp authenticationmail transfer system in phpphp email scriptphp mailphp mail functionphp mail smtp authenticationphp script to send emailphp send emailphp send email smtpphp send html emailphp validate emailphp.ini smtp authenticationransend email using phpsend mailSend mail using PHP script via SMTPsend mail using smtp in php examplesmtp mail function in php example
0 1,505
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Send Free SMS From C#.NET using SMS API?

Next Post

How to Convert a Website into Android Application using Android Studio?

Leave a comment
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.