Showing posts with label Send MAIL. Show all posts
Showing posts with label Send MAIL. Show all posts

Wednesday, December 1, 2010

HTML mailto attribute

The HTML mailto is a quick way to add the facility of receiving feedback from visitor on the web site. when the visitor clicked the HTML mailto, It lanuches their email program with new email window.



Note: HTML mailto assumes that the visitor has configured an email client (Outlook Express, Netscape Messenger, Thunderbird or any other) to send emails.

The Basic form HTML mailto requires an email address.

Its looks like:
<a href="mailto:info@openshell.in">Feedback Form</a>

The Complex form HTML mailto by adding an email subject and the email body so that it looks a little more professional.

Its look Like:
<a href="mailto:info@openshell.in?subject=Feedback for Openshell.in&body=Thanks for Provinding useful Tips">Feedback Form</a>

In addition to the body and subject, we can also provide HTML mailto with CC (Carbon Copy) and BCC (Blind Carbon Copy). This, as you would have guessed, requires us to append these values to the HTML mailto attribute just like we had done for body and subject.

Its look Like:
<a href="mailto:info@openshell.in?subject=Feedback for Openshell.in&body=Thanks for Provinding useful Tips&cc=anotheremailaddress@anotherdomain.com&bcc=onemore@anotherdomain.com">Feedback Form</a>

HTML mailto is a quick and easy way for beginners and who don't know server-side programming languages (such as JSP, PHP, ROR etc.) to add a link on their web site for receiving visitor feedback.

Tuesday, November 23, 2010

Send HTML Mail With PHP

Sending html email in php is extremely easy. All you have to do is call the “mail” function with some extra header.

Have a look on example:
<?php
//define the receiver of the email
$to = 'youraddress@example.com';

//define the subject of the email
$subject = 'Test HTML email';

//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";

//define the body of the message.
ob_start(); //Turn on output buffering
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

echo $random_hash;

//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();

//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );

//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>