How to send Email Using PHP

Sending emails using php on your web-server is not such a big task if you are familiar with basic functions of PHP.

You can write a mail function and provide subject, message as parameter to it.
This mail function is inbuilt and your can use it by using the keyword  main() in your code.

How to use Mail() function in PHP?

Open your PHP file in any editor such as Notepad. If you dont have any existing PHP file, then create new PHP file and start writing the code given below one by one while understanding its use.

Mail to Variable:

$email="email_addressof_the_person_you_want_to_send_mail@domain.com";

The variable "$email" is used to store the address of the person who will recieve the email.

Subject Variable:

$subject="SUBJECT OF THE E-MAIL";

We will use this variable "$subject" to store the value for e-mail. Here I have given the value itself as "SUBJECT OF THE E-MAIL" for simplicity.

Message Variable:

$message="WRITE YOUR MESSAGE HERE";

"$message" variable would hold the value for the message of email. 

Mail Function Inplementation:

mail($email, $subject, $message, "From: <youremailid@domain.com>\r\n");

This is the main function used to send email. It contains 4 parameters here. Now, use these variables and functions in your php file and start sending e-mails from your own server or website.

Below is the complete look of the php sample page:

<?php

$email="receiver@gmail";
 
$subject="Mail function's testing";
 
$message="Testing of mail function on my server was successfull. Thanks";
 
mail($email, $subject, $message, "From: <youremailid@domain.com>\r\n");
 
echo "Mail Sent!";

?>

Try out the above sample script by replacing $email variable's value with your email address and check whether your have received the email or not. 

That's all. If you are getting any error in code above, feel free to comment below.

0 comments:

Post a Comment

Your Comment Here!.....

Categories

10th 3i InfoTech Academic Books Accenture ACIO ActiveX ADT Agricultural AIEEE Air Force Algebraic Amdocs Android Answers Application Development Aptitude Aptitude Questions Architectures ASP ATOS B.Sc B.Tech.B.E. Bank Exam BCA BE Board Exam Books break-continue Business Plan C C Programming C# C++ Campus campus interview Candidate profile Capgemini Career CDS Certification CET Challenge Circle Cisco class code Cognizant communication Company Company Profile Competitive Exams computer Computer Networks concentric circles constructor Course Credit Suisse CSS CTS Data Structure DBMS DC Deloitte difficult interview questions dimensions Distributed Computing do while dotNet Download ds Dynamic Web Development e-Admit card Educational engineering entertainment Even Odd Events exam schedule exception for loop fresher GATE general Discussion general knowledge Get Placed Government Job Hall Ticket HCL how to answer How to Prepare HR HR Interview HSC hypertext preprocessor IB IBM IBPS IIT Indian Army Information infosys Intelligence Bureau Internship interview Experience interview questions Interview Tips IntroC IntroC# IntroJava IntroPHP IT J2EE J2ME Java JavaScript jobs Language Books Language Tutorial Languages limit number of objectsJava Limit the number of objects being created in JAVA Linux Linux Administrator Linux Developer Logical Questions loops M Tech M.E. M.Tech M.Tech AND B.Tech Management Management Skills Matrices MBA mca ME microsoft mistakes Mixture Mobile Computing mock questions mock test MySql naukri NDA OOP opening Operating System Oracle paper Persistent PHP php programming php string variables PL/SQL Placement placement guide Placement Paper Placement Process preparing for placement presentation probability Problems Professional program Programming Project Engineer project idea Projects Puzzle qualities Question of the day Questions Quiz Question Recruitment Recruitment Pattern Requirement Result Resume Reviews Screen Sizes Scripting Session Skills Software Software Engineering solved papers Source Code Speed time and distance SQL SSC story Stress Interview Study Material study tips submit resume Synonym TCS Tech Mahindra tech news Technical Books Technical Interview Testing thank you letter Thought Time Table TutC++ Unix questions asked in aptitude and inteviews for MCA UPSC verbal Web Designing Web Developer Website Development What to read while loop Wipro Writing Resume

Receive Quality Tutorials Straight in your Inbox by submitting your Email ID below.

Categories

10th 3i InfoTech Academic Books Accenture ACIO ActiveX ADT Agricultural AIEEE Air Force Algebraic Amdocs Android Answers Application Development Aptitude Aptitude Questions Architectures ASP ATOS B.Sc B.Tech.B.E. Bank Exam BCA BE Board Exam Books break-continue Business Plan C C Programming C# C++ Campus campus interview Candidate profile Capgemini Career CDS Certification CET Challenge Circle Cisco class code Cognizant communication Company Company Profile Competitive Exams computer Computer Networks concentric circles constructor Course Credit Suisse CSS CTS Data Structure DBMS DC Deloitte difficult interview questions dimensions Distributed Computing do while dotNet Download ds Dynamic Web Development e-Admit card Educational engineering entertainment Even Odd Events exam schedule exception for loop fresher GATE general Discussion general knowledge Get Placed Government Job Hall Ticket HCL how to answer How to Prepare HR HR Interview HSC hypertext preprocessor IB IBM IBPS IIT Indian Army Information infosys Intelligence Bureau Internship interview Experience interview questions Interview Tips IntroC IntroC# IntroJava IntroPHP IT J2EE J2ME Java JavaScript jobs Language Books Language Tutorial Languages limit number of objectsJava Limit the number of objects being created in JAVA Linux Linux Administrator Linux Developer Logical Questions loops M Tech M.E. M.Tech M.Tech AND B.Tech Management Management Skills Matrices MBA mca ME microsoft mistakes Mixture Mobile Computing mock questions mock test MySql naukri NDA OOP opening Operating System Oracle paper Persistent PHP php programming php string variables PL/SQL Placement placement guide Placement Paper Placement Process preparing for placement presentation probability Problems Professional program Programming Project Engineer project idea Projects Puzzle qualities Question of the day Questions Quiz Question Recruitment Recruitment Pattern Requirement Result Resume Reviews Screen Sizes Scripting Session Skills Software Software Engineering solved papers Source Code Speed time and distance SQL SSC story Stress Interview Study Material study tips submit resume Synonym TCS Tech Mahindra tech news Technical Books Technical Interview Testing thank you letter Thought Time Table TutC++ Unix questions asked in aptitude and inteviews for MCA UPSC verbal Web Designing Web Developer Website Development What to read while loop Wipro Writing Resume