Child pages
  • How To Use The PHP Mail Function
Skip to end of metadata
Go to start of metadata

This article will detail how to use the PHP Mail Function.

Not all of the UK2 clients want to use the UK2 Formmail function, and as a result you are able to use a PHP Script that uses the PHP Mail function to send emails from your Web Hosting Package to your email address.

Here we have provided an example of a basic PHP Mail contact form that can be used. For this to work correctly call the file “contact.php”

 that you will need to change the email@yourdomain.co.uk to your email address so that the email message is sent to you.

 

 

Within the contact.php file your will place the following code: <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("email@yourdomain.co.uk", "$subject", $message, "From:" . $email); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='contact.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> This is how the example above works:

  • First, check if the email input field is filled out
  • If it is not set (like when the page is first visited); output the php form
  • If it is set (after the form is filled out); send the email from the form

When submit is pressed after the form is filled out, the page reloads, sees that the email input is set, and sends the email and refreshes the page to show “Thank you for using our mail form”. **If you make any changes to this email script the UK2 Technical Support team cannot offer support with the customization. We will be able to ensure that the PHP Mail function is available for you on your particular server** If you encounter any errors or problems with this process, please contact our technical support department. They will be happy to help resolve any issues you experience.