Have you ever wondered how an email message is programmatically sent out from an application? Here I will show three different ways that sent email can be coded in different software platforms.
The first programming snippet comes from a Windows Phone mobile app. It’s actually quite simple. This is for Windows Phone 8 and the C# Sharp coding. An email account needs to first be set up on the phone.
- view plainprint?
- // create email object.
- EmailComposeTask emailComposeTask = new EmailComposeTask();
- // add a subject.
- emailComposeTask.Subject = "test subject";
- // add a message.
- emailComposeTask.Body = "test message";
- // add a recipient.
- emailComposeTask.To = "[email protected]";
- // add a carbon copy recipient.
- emailComposeTask.Cc = "[email protected]";
- // add a blind carbon copy recipient.
- emailComposeTask.Bcc = "[email protected]";
- // bring up the email interface.
- emailComposeTask.Show();
- <?php
- session_start();
- // include this php file to process the ‘captcha’ code to verify the
- // sender is human, not a robot.
- include("simple-php-captcha.php");
- // initialize php error variables to check for valid fields of information.
- $flagvar = 0;
- $flagvar1 = 0;
- $flagvar2 = 0;
- $flagvar3 = 0;
- $flagvarx = 0;
- // assign the auto generated ‘captcha’ code to a
- // php session variable used to display it to the email sender.
- $_SESSION['captcha'] = captcha();
- // enter here after the user clicks the ‘Submit’ button
- // to send out the email.
- if ($_POST['submit_email']) {
- // check the sender’s email address to make sure it is valid and set error variables.
- if(strlen($_POST['EMAIL']) <= 0) {
- $flagvar1 = 1;
- $flagvar = 1;
- } else if (!preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $_POST['EMAIL'])) {
- $flagvar1 = 1;
- $flagvar = 1;
- }
- // make sure there is something in the subject line and set error variables.
- if ( emptyempty($_POST['SUBJECT']) ) {
- $flagvar2 = 1;
- $flagvar = 1;
- }
- // make sure there is something in the message body and set error variables.
- if ( emptyempty($_POST['MESSAGEBOARD']) ) {
- $flagvar3 = 1;
- $flagvar = 1;
- }
- // ‘captcha’ codes match, then proceed.
- if ( $_REQUEST['skip_CaptchaCode'] === $_SESSION['firstcaptcha'] && $flagvar == 0 ) {
- // take out all html and php tags from the message body.
- $text = strip_tags($_POST['MESSAGEBOARD']);
- // concatenate two line feeds followed by the text “Email Sender”
- // followed by the sender’s email address.
- $text = $text."\n\nEmail Sender: ".$_POST['EMAIL'];
- // set the headers to nothing.
- $headers = "";
- // use the php mail function to send the email to my email address so
- // I can receive inquiries from prospective customers.
- mail('[email protected]', $_POST['SUBJECT'], $text, $headers);
- // display my web page to notify the sender that the submitted email has
- // been successfully sent to me.
- header("Location: http://www.analyzohiosoftware.com/email-verify.html");
- }
- // ‘captcha’ codes do not match, so set an error flag.
- if ( $_REQUEST['skip_CaptchaCode'] != $_SESSION['firstcaptcha'] ) {
- $flagvarx = 1;
- }
- }
- ?>

Join the conversation! Your thoughts help the community grow.