Tengo el siguiente formulario Template en my tema de wordpress para agregar un formulario al final de mi pagina de contacto:
Código PHP:
<?php
/**
* Template Name: Contact Template
*
*/
if (isset($_POST['submit'])){
/**
* Validar y enviar formulario
*/
if(trim($_POST['name']) === ''){
$nameError = __('Please enter your name.');
$hasError = true;
} else {
$name = trim($_POST['name']);
}
if(trim($_POST['email']) === ''){
$emailError = __('Please enter your email.');
$harError = true;
} elseif(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$emailError = __('Please enter a valid email address.');
$harError = true;
} else {
$email = trim($_POST['email']);
}
if(trim($_POST['zip']) === ''){
$zipError = __('Please enter your zip code.');
$hasError = true;
} else {
$zip = trim($_POST['zip']);
}
if(!(trim($_POST['address']) === '')){
$address = trim($_POST['address']);
} else {
$address = 'N/A';
}
if(!(trim($_POST['company']) === '')){
$company = trim($_POST['company']);
} else {
$company = 'N/A';
}
if(!(trim($_POST['city']) === '')){
$city = trim($_POST['city']);
} else {
$address = 'N/A';
}
if(!(trim($_POST['state']) === '')){
$state = trim($_POST['state']);
} else {
$state = 'N/A';
}
if(!(trim($_POST['phone']) === '')){
$phone = trim($_POST['phone']);
} else {
$phone = 'N/A';
}
if(!isset($hasError)){
$emailTo = "[email protected]";
$subject = "[Contact Form] From: " . $name;
$body = "Name: " . $name . "\n\n";
$body .= "Email: " . $email . "\n\n";
$body .= "Company: " . $company . "\n\n";
$body .= "Address: " . $address . "\n\n";
$body .= "City: " . $city . "\n\n";
$body .= "State: " . $state . "\n\n";
$body .= "Zip: " . $zip . "\n\n";
$body .= "Phone: " . $phone . "\n\n";
$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
if(mail($emailTo, $subject, $body, $headers)){
$emailSent = true;
}
}
}
get_header(); ?>
<div id="container" class="one-column">
<div id="content" role="main">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if (!is_page ()): ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php endif; ?>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
<?php endwhile; ?>
<p>
<?php _e('* Important: At this time we only service small to medium businesses with
at least 5 or more PCs. We do not service home users.'); ?>
</p>
<p>
<?php _e('Fields in '); ?><span class="red"><?php _e('RED'); ?></span><?php _e(' are required.'); ?>
</p>
<div id="form-area">
<?php if (isset($emailSent) && $emailSent == true): ?>
<div id="success">
<p><?php _e('Thanks, your email was sent successfully.'); ?></p>
</div>
<?php else : ?>
<?php if (isset($hasError)): ?>
<div class="error">
<p><?php _e('Sorry an error ocurred.'); ?></p>
</div>
<?php endif; ?>
<form action="<?php the_permalink(); ?>" method="post" id="contact-form" name="contact-form">
<table>
<tr>
<td><label class="red" for="email"><?php _e('Email'); ?></label></td>
<td>
<input type="text" name="email" id="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
<?php if ($emailError != ''): ?>
<span class="error red"><?php echo $emailError; ?></span>
<?php endif; ?>
</td>
</tr>
<tr>
<td><label class="red" for="name"><?php _e('Contact Name'); ?></label></td>
<td>
<input type="text" name="name" id="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" />
<?php if ($nameError != ''): ?>
<span class="error red"><?php echo $nameError; ?></span>
<?php endif; ?>
</td>
</tr>
<tr>
<td><label for="company"><?php _e('Company'); ?></label></td>
<td><input type="text" name="company" id="company" value="<?php if (isset($_POST['company'])) echo $_POST['company']; ?>" /></td>
</tr>
<tr>
<td><label for="address"><?php _e('Address'); ?></label></td>
<td><input type="text" name="address" id="address" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>" /></td>
</tr>
<tr>
<td><label for="city"><?php _e('City'); ?></label></td>
<td><input type="text" name="city" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></td>
</tr>
<tr>
<td><label for="state"><?php _e('State'); ?></label></td>
<td><input type="text" name="state" id="state" value="<?php if (isset($_POST['state'])) echo $_POST['state']; ?>" /></td>
</tr>
<tr>
<td><label class="red" for="zip"><?php _e('Zip Code'); ?></label></td>
<td>
<input type="text" name="zip" id="zip" size="5" value="<?php if (isset($_POST['zip'])) echo $_POST['zip']; ?>" />
<?php if ($zipError != ''): ?>
<span class="error red"><?php echo $zipError; ?></span>
<?php endif; ?>
</td>
</tr>
<tr>
<td><label for="phone"><?php _e('Phone'); ?></label></td>
<td><input type="text" name="phone" id="phone" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" id="submit" value="<?php _e('Submit'); ?>" /></td>
</tr>
</table>
</form>
<?php endif; ?>
</div>
</div><!-- #content -->
</div><!-- #container -->
<?php get_footer(); ?>
Alguien sabe que puede estar pasando? Gracias de antemano.