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) )
true else {testresults=
"Please input a valid email address!")alert(
testresults=
false}
if(sub=="")
{
"subject is blank"); return false;alert(
}
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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: PHP E-Mail
Post your Comment