Approaches to Web Development for Bioinformatics

Previous  Contents  Next
References

Sending Email

Users do not like getting spammed by machine generated email. However, email can be the best alternative for a number of functions, such as preventing automated tools from registering as users and notifying users of long running searches. The PHP mail() function can be used to send email to users. It assumes that the email server Sendmail or a wrapper interface for it is on the PATH. Here is a simple example.

PHP

<?php
$to = 'user@example.com';
$subject = 'the subject';
$message = 'hello';
$headers =
'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n"
;

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

print("Message sent to " . $to);
?>

This script sends an email to 'user@example.com' with the subject 'the subject' and message body 'hello'. The message will appear as sent from 'webmaster@example.com'. HTML email can be sent as well by setting the appropriate content type header. This is shown in the following example.

PHP

<?php
$to = 'user@example.com';
$subject = 'Search Results are Ready';
$message = <<< END
<html>
<head>
<title>Search Results are Ready</title>
</head>
<body>
<h1>Search Results are Ready</h1>
<p>
Click <a href='http://localhost/searchresults.php'>here</a> to pick up your search results.
</p>
</body>
</html>
END;

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=utf-8' . "\r\n" .
'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n";

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

print("Message sent to $to.");
?>


Previous  Contents  Next
References

Contributed Comments and NotesAdd a comment.

There are no user comments.

Google

Please send ideas and opinions by email at alexamies@gmail.com.

© 2006-2007 Alex Amies