PHP Sendmail Tutorial

PHP is a programming language that is typically embedded in HTML websites to provide interactive elements. This allows you to perform common programming logic and control flow statements, making it possible to create elaborate websites. In addition to typical programming language functions, PHP contains Internet-specific functions. For example, you can use PHP to send email programmatically. Since this takes advantage of a built-in function, you can send an email with a single statement.

Things You'll Need

  • Computer with PHP server or an online PHP interpreter (see Resource section)
Show More

Instructions

    • 1

      Decide how you will run your PHP code. If you have a PHP server, you can execute code using PHP files. If you do not have access to a PHP server, you can use an online PHP interpreter. Enter the code in this tutorial into either a PHP file or the online PHP interpreter.

    • 2

      Begin your PHP program with the following statement:

      <?php

    • 3

      Declare a string that will contain the subject of your email. You can name the string something logical, like "emailSubject," and assign it a short message like this:

      $emailSubject = 'This is a test email'

    • 4

      Declare a string that will contain the body of the email:

      $emailBody = 'This is the body of the test email'

    • 5

      Send the email using the mail function. Pass in the email address you want to send mail to and the two strings declared previously. The finished statement looks like this:

      mail('anon@email.com', $emailSubject, $emailBody);

    • 6

      Conclude your PHP program with the statement below. Your program is now ready to be tested on your PHP server or online PHP interpreter.

      ?>

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured