Código HTML:
Ver original
<form method="post" action="enviar.php"> <fieldset> <!-- <input type="hidden" name="asuntooculto" value="asuntooculto"> --> <!-- no funciona $subject = jayj_html5_sanitize_string( $_REQUEST['asuntooculto'] ); --> <!-- tampoco funciona if ( mail( $email, "$subject (Asunto personalizado)", --> <select name="menuselect"> </fieldset> </form>
Pasa que al querer extraer las variables con enviar.php, sólo me funciona el envío del mail con la sentencia original o agregado una sola variable más. Luego aparentemente, agregado una sola variable una por una, funciona con todas, pero no juntas. La sentencia original es:
Código PHP:
if ( mail( $email, "$subject", utf8_decode( $message ), "From: $name < $sender>" ) )
Código PHP:
if ( mail( $email, "$subject", $texto1, $texto2, $menuselect, $fechastart, $fechaend, $numero, utf8_decode( $message ), "From: $name < $sender>" ) )
Además, querría poner un asunto predefinido y esconder el campo Asunto en el formulario, pero no hay manera, he intentado con $_REQUEST['asuntooculto'] estando el input del asunto hidden, como pueden ver en el archivo enviar.php:
Código PHP:
<?php
/**
* PHP contact form
*/
// If the form have been submitted and the spam check field is empty
if ( isset( $_POST['email'] ) && empty( $_POST['s_check'] ) ) :
/**
* Enter your email here
*/
$email = '[email protected]';
/**
* Language strings
*/
$strings = array(
'default_subject' => 'Message on your website',
'default_name' => 'Anonymous',
'error_message' => '<strong>Error:</strong> %s cannot be left blank', // %s is the error name
'invalid_email' => '<strong>Error:</strong> Email address is invalid',
'email_success' => 'Gracias! hemos recibido su mensaje',
'email_error' => 'There was a problem sending your email. Please try again'
);
/**
* Required fields
* We'll check and see if any of the required fields are empty.
*/
$required = array(
//'name' => 'Name',
//'subject' => 'Subject',
'email' => 'Email',
'mensaje' => 'Message'
);
// Declare our $errors variable we will be using later to store any errors.
$errors = array();
/**
* Get form values and sanitize them
*/
$name = jayj_html5_sanitize_string( $_POST['nombre'] );
$from = filter_var( $_POST['email'], FILTER_SANITIZE_EMAIL );
$subject = jayj_html5_sanitize_string( $_POST['subject'] );
//$subject = jayj_html5_sanitize_string( $_REQUEST['asuntooculto'] );
//$subject = 'Asunto personalizado tampoco funciona';
$texto1 = jayj_html5_sanitize_string( $_POST['texto-primero'] );
$texto2 = jayj_html5_sanitize_string( $_POST['texto-segundo'] );
$menuselect = jayj_html5_sanitize_string( $_POST['menuselect'] );
$fechastart = jayj_html5_sanitize_string( $_POST['fecha-primero'] );
$fechaend = jayj_html5_sanitize_string( $_POST['fecha-segundo'] );
$numero = jayj_html5_sanitize_string( $_POST['numero'] );
$message = jayj_html5_sanitize_string( $_POST['mensaje'] );
$sender = '[email protected]'; // or another email from your own domain
$message .= "\n Sent from: $from";
// Validate the sanitized email
if ( ! filter_var( $from, FILTER_VALIDATE_EMAIL ) )
$errors[] = $strings['invalid_email'];
// Set a default name
if ( empty( $name ) )
$name = $strings['default_name'];
// Set a default subject
if ( empty( $subject ) )
$subject = $strings['default_subject'];
/**
* Loops through each required $_POST value
* Checks to ensure it is not empty.
*/
foreach ( $required as $key => $value ) :
if ( isset( $_POST[$key] ) && ! empty( $_POST[$key] ) )
continue;
else
$errors[] = sprintf( $strings['error_message'], $value );
endforeach;
/**
* Now check to see if there are any errors
*/
if ( empty( $errors ) ) {
// No errors, send mail using conditional to ensure it was sent.
if ( mail( $email, "$subject", $texto1, $texto2, $menuselect, $fechastart, $fechaend, $numero, utf8_decode( $message ), "From: $name < $sender>" ) )
echo '<p class="alert alert-success">' . $strings['email_success'] . '</p>';
else
echo '<p class="alert alert-error">' . $strings['email_error'] . '</p>';
} else {
// Errors were found, output all errors to the user.
echo '<div class="alert alert-warning">';
echo implode( '<br />', $errors );
echo '</div>';
}
else :
// The user have tried to access thid page directly or is a spambot
die("You're not allowed to access this page directly");
endif;
/**
* Sanitize inputs
*
* @uses FILTER_SANITIZE_STRING Strip tags
* @uses FILTER_FLAG_NO_ENCODE_QUOTES Prevents encoding of quotes
* @uses stripslashes() Removes slashes added to quotes
*
* @since Jayj HTML5 theme 2.1
* @param string $string The string to be sanitized
* @return string The sanitized string
*/
function jayj_html5_sanitize_string( $string ) {
return stripslashes( filter_var( $string, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) );
}
A ver si me podrían ayudar a recibir todos los parámetros por email y a poner un asunto personalizado quitando el input asunto. Gracias de antemano.