-1

I have created a 'Contact Us' form for a SharePoint for a group in work. I created this using HTML and have created a PHP script for the backend to send the form to my email address. How do I go about inserting this PHP into SharePoint so that this works? Below is the HTML and PHP code.

 <span style="color: #00cc99; font-size: 15pt;"><span style="color: #00cc99;">Contact Us if you&#39;re interested in volunteering&#160;with Social Innovation.&#160;</span></span></p>
<table width="450">
   <tbody>
      <tr>
         <td valign="top">
            <label>Name *</label> </td>
         <td valign="top">
            <input type="text" size="30" maxlength="50"/>
         </td>
      </tr>
      <tr>
         <td valign="top">
            <label>Email Address *</label> </td>
         <td valign="top">
            <input type="text" size="30" maxlength="80"/>
         </td>
      </tr>
      <tr>
         <td valign="top">
            <label>Message *</label> </td>
         <td valign="top">
            <textarea maxlength="1000" rows="6" cols="25"></textarea> </td>
      </tr>
      <tr>
         <td colspan="2" style="text-align: center;">
            <input type="button" value="Submit"/>
         </td>
      </tr>
   </tbody>
</table> 
<p>&#160;</p>

    <?php
if(isset($_POST['email'])) {

    // CHANGE THE TWO LINES BELOW TO SUSANNAH
    $email_to = "[email protected]";

    $email_subject = "Sharepoint Volunteer Enquiry";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['message'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $message = $_POST['message']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }
  if(strlen($message) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Message: ".clean_string($message)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

//thank you message 
Thank you for contacting us. We will be in touch with you very soon.

<?php
}
die();
?>

1 Answer 1

0

Sharepoint Site using PHP code

I did it the same way like they suggest in this post using the Page Viewer WebPart.

But as this post is 5 years old, there might be a free php-viewer Webpart by now (as there is a HTML-Viewer)

1
  • If you are using SharePoint 2013 i would suggest implementing a provider hosted app. The only issue with this is, that you would have to implement a trust relation with your PHP Server and SharePoint. But if you have managed this, then you could implement all kinds of SharePoint apps using PHP.
    – Daniel
    Dec 15, 2015 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.