Home Php PHP E-Mail
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

PHP E-Mail

Advertisement
E-Mail is an abbreviation of Electronic Mail, it is a method of passing, exchanging of thoughts.

PHP E-Mail

     

E-Mail is an abbreviation of Electronic Mail, it is a method of passing, exchanging of thoughts. With the help of E-mail we can send  various types of attachments, like .doc, .xls. .pdf etc. file

With the help of PHP we can send mails to another person. Given example will illustrates the way we can send mail, in the current example we use, PHP, JavaScript, and html scripts.


(Note: The given example is just a program to send mail, but it is not sufficient enough to send mail to another mail address, we need mail server and various other application to send a mail successfully )

Example:

<?php

if(isset($_REQUEST['user']))

{

$to=$_REQUEST['user'];

$subject=$_REQUEST['subject'];

$msg=$_REQUEST['msg'];

$from="rose@roseindia.com";

$headers="From:$from";

mail($to,$subject, $msg,$headers);

echo"Mail successfully sent";

}

else{

?>

<html>

<head>

<title>

My Email

</title>

<script type="text/javascript">

 

function validation()

{

var to=document.form.user.value;

var filter=/^.+@.+\..{2,3}$/

var sub=document.form.subject.value;

if (filter.test(to) )

testresults=true

else {

alert("Please input a valid email address!")

testresults=false

}

 

if(sub=="")

{

alert("subject is blank");

return false;

}

 

return (testresults)

 

}

</script>

</head>

<body>

<center>

<form name="form" onsubmit="return(validation())" action="mailPhp.php">

<table>

<tr>

<td>To:</td><td><input type="text" name="user" ></td>

</tr>

<tr>

<td>Subject:</td><td><input type="text" name="subject"></td>

</tr>

<tr>

<td>Message</td>

<td><textarea name='msg' rows="8" cols="12"></textarea></td>

</tr>

<tr>

<td><input type ="submit" value="submit"></td>

<td><input type="reset" value="Reset"></input></td>

</tr>

</table>

</form>

</center>

</body>

</html>

<?php }?>

 

Output:

If we left the subject box and to box blank or the email address is wrong, then alert box will be generated.

 

Since we did not install the mail server, output will be as follows:
Mail successfully sent

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 12, 2009

Ask Questions?    Discuss: PHP E-Mail  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Sakthivel
December 5, 2011
I'm in need help in using php and mysql

I'm in need help in using php and mysql.I want to know how to get permium user
brajesh
February 9, 2012
for advice

this code is very help full for creating email
Prakash
December 13, 2012
Gmail compose mail plugins

i want to click the send button plugins to gmail compose mail to open the gmail compose mail send using php code
DMCA.com