# sendmail.php

**URL:** <https://www.phphelp.com/t/sendmail-php/35896>\
**Category:** Beginners - Learning PHP\
**Created:** [December 4, 2023, 7:27pm UTC](https://www.phphelp.com/t/sendmail-php/35896 "2023-12-04T19:27:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlyne](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@charlyne](https://www.phphelp.com/u/charlyne)\
**Post date:** [December 4, 2023, 7:27pm UTC](https://www.phphelp.com/t/sendmail-php/35896/1 "2023-12-04T19:27:38Z")

</div>

Hello everyone,  
I would like you to tell me what error the sendmail file contains because it detects an error on the $siteOwnersEmail function  
I don’t know the syntax for entering my address  
Thank you for your answers

```auto
<?php

if($_POST) {

    $name = trim(stripslashes($_POST['contactName']));
    $email = trim(stripslashes($_POST['contactEmail']));
    $subject = trim(stripslashes($_POST['contactSubject']));
    $contact_message = trim(stripslashes($_POST['contactMessage']));

    // Check Name
    if (strlen($name) < 2) {
        $error['name'] = "Please enter your name.";
    }
    // Check Email
    if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
        $error['email'] = "Please enter a valid email address.";
    }
    // Check Message
    if (strlen($contact_message) < 15) {
        $error['message'] = "Please enter your message. It should have at least 15 characters.";
    }
    // Subject
    if ($subject == '') { $subject = "Contact Form Submission"; }

    // Set Message
    $message .= "Email from: " . $name . "<br />";
    $message .= "Email address: " . $email . "<br />";
    $message .= "Message: <br />";
    $message .= $contact_message;
    $message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

    // Set From: header
    $from = $name . " <" . $email . ">";

    // Email Headers
    $headers = "From: " . $from . "\r\n";
    $headers .= "Reply-To: ". $email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    if (!$error) {

        ini_set("sendmail_from", $siteOwnersEmail); // for windows server
        $mail = mail($siteOwnersEmail, $subject, $message, $headers);

        if ($mail) { echo "OK"; }
        else { echo "Something went wrong. Please try again."; }
        
    } # end if - no validation error

    else {

        $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
        $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
        $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
        
        echo $response;

    } # end if - there was a validation error

}

?>
```

---

<div class="post-metadata">

**Author:** ![salnazi](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@salnazi](https://www.phphelp.com/u/salnazi)\
**Post date:** [January 19, 2024, 2:44am UTC](https://www.phphelp.com/t/sendmail-php/35896/2 "2024-01-19T02:44:52Z")

</div>

By the way, $siteOwnersEmail is not function. its variable u need declare

current :

$name = trim(stripslashes($\_POST[‘contactName’]));

$email = trim(stripslashes($\_POST[‘contactEmail’]));

$subject = trim(stripslashes($\_POST[‘contactSubject’]));

$contact\_message = trim(stripslashes($\_POST[‘contactMessage’]));

add more :

$name = trim(stripslashes($\_POST[‘contactName’]));

$email = trim(stripslashes($\_POST[‘contactEmail’]));

$subject = trim(stripslashes($\_POST[‘contactSubject’]));

$contact\_message = trim(stripslashes($\_POST[‘contactMessage’]));

$siteOwnersEmail = “[example@example.com](mailto:example@example.com)” // ur email address
