PHP Research And Development

Sharing PHP Script, PHP News, Download web application, web tutorial, Learning PHP and more

Sending Email with PHP  

A Contact Us page with a HTML form to contact the
webmaster adds a nice personal touch to any website. Users feel
"connected" to the owner and it makes them seems more down-to-earth.

PHP
comes with a handy function called, would you believe it, mail(). Here
you will learn how to use it in it's most simple form to send a basic
email.

Please note that if your server doesn't have PHP installed, this will not work. That means Google-Pages too.

Now, to get started. Instructions are given in the comments.

Save the following as sendEmail.php

<br/> &amp;lt;?php<br/> // Did someone click submit?<br/> if($_POST['submit'];)<br/> {<br/> // Get our form variables.<br/> $subject = $_POST['subject'];<br/> $email = $_POST['email'];<br/> $msg = $_POST['comments'];<br/> // Send the email with the mail function.<br/> // Replace example@domain.com with your email address!<br/> if( mail("example@domain.com", "$subject", "$email", "$msg") ){<br/> // We have lift-off!<br/> echo "Email sent successfully!";<br/> } else {<br/> echo "Oops! Mail couldn't be sent.";<br/> }<br/> }<br/> ?&amp;gt;<br/>

You
can now make a HTML page that lets a user send you an email, by
including the following HTML code in your page. (The following code
goes in between the

&amp;lt;body&amp;gt;&amp;lt;/body&amp;gt; tags).

<br/> &amp;lt;form method="post" action="sendEmail.php"&amp;gt;<br/> Subject:<br/> &amp;lt;input type="text" name="subject" size="20"&amp;gt;<br/> Email:<br/> &amp;lt;input type="text" name="email" size="20"&amp;gt;<br/> Comments:<br/> &amp;lt;textarea cols="20" rows="5" name="comments"&amp;gt;<br/> &amp;lt;/form&amp;gt;<br/>

Ankur Kothari is the Director of the newly developed Lipidity Corporation,
which provides free website design. Ankur has a deep knowledge and
mastery of PHP, and has been programming since he was twelve years old.

AddThis Social Bookmark Button

0 comments

Post a Comment