Jump to content

[SOLVED] PHP novice needing help


tomstirling1979

Recommended Posts

I am trying to create a form on my website that sends an email to the specific email address of my choice. I also need to create a "success message" that displays when the user submits there information, but that the message simply appears under the form on the same page, and not on a new page. I had this working before, and then I had to switch the site to goDaddy and then I no longer got the success message.

 

I am a total novice and just need some advice to get this fixed fast.

 

The code is below for people to examine.

 

 

 

<?php

 

$email = '[email protected]'; // email who you're sending to

$subject = $_POST['subject']; //email subject

$headers = 'From: Clearly Creative Homepage Leads' . "\r\n" .

    'Reply-To: [email protected]' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

 

$message = '';

$errorStr = '';

 

if(isset($_POST['submit'])) {

 

  /* define required fields */

  $requiredFields = array(

'Company Name' => 'companyname',

'Name' => 'name',

'EMail' => 'email',

'Message' =>'message'

);

 

  /* valudate required fields */

  foreach($requiredFields as $key => $value) {

  if($_POST[$value] == '') {

  $errorStr .= "Error: Field $key is required <br />";

}

  }

  /* if all fields validated, send the email */

 

  if($errorStr == '') {

    /* Create Message */

$messageFields = array(

'Company Name' => $_POST['companyname'],

'Name' => $_POST['name'],

'E-Mail' => $_POST['email'],

'Message' => $_POST['message']

                          );

 

foreach($messageFields as $key => $value) {

$message .= "$key : $value  \n";

}

   

    mail($email, $subject, $message, $headers);

$sent = 1;

  }

 

}

 

?>

 

 

 

 

<!-- this is the form starting-->

 

<form action="index_sidebar_test.php" method="POST">

 

<font class="sidebarDate">Company Name *</font><br />

<input width="200" name="companyname" type="text"/><br />

 

<font class="sidebarDate">Full Name *</font><br />

<input width="200" name="name" type="text" /><br />

 

<font class="sidebarDate">Email Address *</font><br />

<input width="200" name="email" type="text" />

<br />

 

<font class="sidebarDate">Message *</font><br />

<textarea cols=20 rows=4 name="message" /></textarea>

<br /><br />

 

 

<input type="submit" value="Submit" name="submit"/></form>

 

<?php 

if($sent == 1 && isset($_POST['submit']) ) {\

?>

  <span class="Main_HeadingText">Thanks for your submission.<br />

  We’ll get back to you within one business day.</span>

 

<?

} elseif ($errorStr != '') {

    print $errorStr;

    }

 

?>

 

<!-- this is the form ending -->

Link to comment
https://forums.phpfreaks.com/topic/144714-solved-php-novice-needing-help/
Share on other sites

change the <? to <?php in the following code

 

<?
                                } elseif ($errorStr != '') {
                                    print $errorStr;
                                 }

                                ?>

 

I dont think that godaddy supports php short tags. I never got them to work.

 

Also use [ code] [ /code] tags (without the space) it color codes things and makes it easier to read.

 

Also what is the \ for here

 

if($sent == 1 && isset($_POST['submit']) ) {\

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.