This is my first time working with php. I used a sample php mail code to process the mail. After entering in the form info and hit the send it button should show a new window that the mail was sent. The email does not send with the contents from the input fields. I left my email out in the top of this code.

I just relaized at the time of this writing I do not have a thanks.htm so will create this file. The php is not sending the mail and is residing on my linux server with php server running on it. The server currently as freepbx on it and its mail function works when it recieves a voice mail message and sends me a mail message.

<?php
/* Set e-mail recipient */
$myemail  = "myemail@yahoo.com";

/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$phonenumber  = check_input($_POST['phonenumber'], "Enter your phone number");
$company    = check_input($_POST['company'],"Company name");
$subject  = check_input($_POST['subject'],"Enter in comments");


/* If e-mail is not valid show error message */
if (!preg_match("/([\\w\\-]+\\@[\\w\\-]+\\.[\\w\\-]+)/", $email))
{
    show_error("E-mail address not valid");
}


/* Let's prepare the message for the e-mail */
$message = "Hello!

Your contact form has been submitted by:

Name: $yourname
Phonenumber: $phonenumber
Company: $company
Subject:$subject

End of message
";


/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php








<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

        <html xmlns="http://www.w3.org/1999/xhtml">
<head><title>example site layout</title>
    <title>example site layout</title>
                 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
           <link rel="stylesheet" type="text/css"  href="style.css"/>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<link rel="stylesheet" type="text/css"  href="style.css"/>
</head>
<body>
 <div id="container">
    <div id="header">
            <div id="logo">
                <img width="315" height="90"  alt="example" src="Logo.png" />
            </div>
            <div id="contact">   
                    <p>Contact us today</p>
                    <p>Office: 604-xxx-xxxxx</p> 
            </div>
        </div>       
 <div id="content">
  <p>Please contact us regarding our Products and Services</b></p>
    <div id="form">
    <form action="contact.php" method="post">
     <p><b>Your Name:</b> <input type="text" name="yourname" /><br />
     <p><b>Phone Number:</b><input type="text" name="phonenumber" /><br /> 
     <p><b>Company Name:</b><input type="text" name="company" /><br />
     <b>Subject:</b> <input type="text" name="subject" /><br />
     <p><b>Your comments:</b><br />
     <textarea name="comments" rows="10" cols="40">
  </form>
</div> 

</div>
<div id="footer"></div>
</div>
</body>
</html>

Recommended Answers

All 2 Replies

Your mail function is not correct.

Example:

$to = $_POST['user_email'];

$subject = "Password Recovery";

$message = "<b>Password Recovery Program.</b>";
$message .= "<p>New Password: ".$gen_rand_pass."</p>";

$header = "From:no-reply@somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";

$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}

There are many posts on this topic if you search on Google. This post just explains the steps. The above post is may help you. Php development is awesome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.