1

Tengo un formulario de contacto en html en una pagina de wordpress, el contact.php que es el action del form, esta en la raiz pero cuando le doy al boton de enviar me da un error 500, a que se debe este error?

el contact.php que es donde enviamos el correo etc, ha de estar en un sitio especifico?

Codigo html que tengo en una pagina:

<form action="contact_lawyers-nuevalp.php" name="contactform" class="form" method="post">
<p><span class="usuario"></span><input id="name" class="form-control" type="text" name="first_name" placeholder="Enter your Name"> </p>
<p><span class="email"></span><input id="email" class="form-control" type="text" name="email" placeholder="Enter your Email"> </p>
<p><span class="telefono-form"></span><input id="phone" class="form-control" type="text" name="phone" placeholder="Enter your Phone Number"> </p>
<p><textarea id="comments" class="form-control" name="message" rows="6" placeholder="Hi, I would like to know ..."></textarea></p>
<p><input type="submit" value="Get a Free Consultation" id="submit"></p>
<p><input type="hidden" id="gclid_field" name="gclid_field" value=""></p>
</form>

Codigo PHP que envia el correo:

<head>

    <!-- Basic -->
    <meta charset="utf-8">
    <title>Carbray</title>
    <meta name="author" content="DSA79">
    <meta name="norobots" content="noindex,nofollow">
    <meta name="keywords" content="responsive, html5 template, one page, landing, startup, business, company, corporate, creative">
    <meta name="description" content="Crossway - Startup Landing Page Template">        

    <!-- Libs CSS -->
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />

    <!-- Google Fonts -->   
    <link href='http://fonts.googleapis.com/css?family=Lato:400,900italic,900,700italic,400italic,300italic,300,100italic,100' rel='stylesheet' type='text/css'>


</head>

<body>

    <div id="contentForm">
<?php
session_start();
        header('Content-Type: text/html; charset=utf-8');

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


            // EDIT THE 2 LINES BELOW AS REQUIRED

            $email_to = "[email protected]";

            $email_subject = "Landing English Lawyers 3.0";
             $email_subject_client = "Thank you for contacting us.";

            $headers_cliente = "Content-Type: text/html; charset=UTF-8\n";  //Con esta cabecera lo que hacemos es que el contenido html se vea 
            $_SESSION['nombre'] = $_POST['first_name']; // required 
            $_SESSION['email'] = $_POST['email']; // required
            $_SESSION['phone'] = $_POST['phone']; // required
            $_SESSION['mensaje']= $_POST['message']; // required
            $_SESSION['gclid'] = $_POST['gclid_field'];//obtenemos el gclid del campo gclid-field
            $landingP=$_SERVER['HTTP_REFERER'];//obtenemos la ruta de donde viene por las cabeceras http        



            $email_message = "Form details below.\n\n";


            function clean_string($string) {
                $bad = array("content-type","bcc:","to:","cc:","href");
                return str_replace($bad,"",$string);
            }


            $email_message .= "Name: ".clean_string($_SESSION['nombre'])."\n";
            $email_message .= "Email Address: ".clean_string($_SESSION['email'])."\n";
            $email_message .= "Phone: ".clean_string($_SESSION['phone'])."\n";
            $email_message .= "Message: ".clean_string($_SESSION['mensaje'])."\n";

            $email_message2 .= "
             <!DOCTYPE html> 
            <html> 
                     <head> 
                           <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
                           <title>Enviar email</title>
                        <style>
                            <!--/* Font Definitions */
                                @font-face
                                    {font-family:'Cambria Math';
                                    panose-1:2 4 5 3 5 4 6 3 2 4;}
                                @font-face
                                    {font-family:Calibri;
                                    panose-1:2 15 5 2 2 2 4 3 2 4;}
                                @font-face
                                    {font-family:Tahoma;
                                    panose-1:2 11 6 4 3 5 4 4 2 4;} 
                                    p.fuente-mail,span.fuente-mail,strong.fuente-mail,span.fuente-mail{font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;}
                                    .imagen-logo{float: right;width: 42%;margin-top: 2%;}
                        </style>  
                     </head> 

                     <body> 
                     <div>
                      <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Dear ".clean_string($_SESSION['nombre']).",</p> 
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Thank you for contacting us.</p><br/>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Our team of professionals have received your inquire and will be in contact with you shortly.</p>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>As one of the leaders in resolving legal issues for international clients, Carbray is proud to represent you in your case, working with you to achieve the most positive outcome.</p>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Thank you for choosing us, and a warm welcome from us all.</p>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Best regards,</p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Name: ".clean_string($_SESSION['nombre'])." </p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Email Address: ".clean_string($_SESSION['email'])." </p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Phone: ".clean_string($_SESSION['phone'])."</p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Message: ".clean_string($_SESSION['mensaje'])."</p>
                     </div>
                     <div> <img class='imagen-logo' style='float: right;width: 42%;margin-top: 2%;' src='http://www.carbray.es/landing_carbray/english/img/logocarbray.png'/></div>
                        <div style='float:left;    width: 50%!important;'>     <div style='float:left'><br/><br/><strong class='fuente-mail' style='<font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Barcelona</strong><br/><span style='font-size:12px' class='fuente-mail'>Ronda Sant Pere, 33 Ppal. 3ª y 4ª,<br/>08010 | Tlf.  +34 93 488 09 72</span></div>
                         <div style='float:left;margin-top: 7.5%;padding-left: 4%;'><strong class='fuente-mail'>Madrid Office</strong> <br/><span style='font-size:12px
                         ;font-family:'Calibri','sans-serif';color:#1F497D;' class='fuente-mail'>Paseo de la Castellana, 18 Planta 7ª,<br/>28046 | Tlf.  +34 91 794 28 10</span></div></div>

                         <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'><strong class='fuente-mail'>Disclaimer:</strong> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Your must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient.    </p>
</div>
                     </body> 
                 </html>";

            $headers = "From: ".$_SESSION['email']."\r\n";
    $headers .= 'Bcc: [email protected]' . "\r\n";
    $headers_cliente .= "From: Info Carbray <[email protected]>\r\n".'X-Mailer: PHP/' . phpversion();


            @mail($email_to, $email_subject, $email_message, $headers);
            @mail($_SESSION['email'], $email_subject_client,     $email_message2, $headers_cliente);                



            /*Message sent! (change the text below as you wish)*/
            header('Location: http://www.carbray.es/landing_carbray/en/thanks.php'); 

             /*End Message Sent*/

            }else
            {

            }
?>
</div>



<div id="contentForm">
<?php

        header('Content-Type: text/html; charset=utf-8');

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


            // EDIT THE 2 LINES BELOW AS REQUIRED

            $email_to2 = "[email protected]";

            $email_subject2 = "Landing English Lawyers  SUB 3.0";
             $email_subject_client3 = "Thank you for contacting us.";

            $headerscliente3 = "Content-Type: text/html; charset=UTF-8\n";  //Con esta cabecera lo que hacemos es que el contenido html se vea 
            $_SESSION['nombre2'] = $_POST['first_name2']; // required 
            $_SESSION['email2'] = $_POST['email2']; // required
            $_SESSION['phone2'] = $_POST['phone2']; // required
            $_SESSION['mensaje2'] = $_POST['message2']; // required
            $_SESSION['gclid'] = $_POST['gclid_field2']
            $landingP2=$_SERVER['HTTP_REFERER'];//obtenemos la ruta de donde viene por las cabeceras http       


            $email_message4 = "Form details below.\n\n";


            function clean_string($string) {
                $bad = array("content-type","bcc:","to:","cc:","href");
                return str_replace($bad,"",$string);
            }


            $email_message4 .= "Name: ".clean_string($_SESSION['nombre2'])."\n";
            $email_message4 .= "Email Address: ".clean_string($_SESSION['email2'])."\n";
            $email_message4 .= "Phone: ".clean_string($_SESSION['phone2'])."\n";
            $email_message4 .= "Message: ".clean_string($_SESSION['mensaje2'])."\n";


            $email_message3 .= "
             <!DOCTYPE html> 
            <html> 
                     <head> 
                           <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
                           <title>Enviar email</title>
                        <style>
                            <!--/* Font Definitions */
                                @font-face
                                    {font-family:'Cambria Math';
                                    panose-1:2 4 5 3 5 4 6 3 2 4;}
                                @font-face
                                    {font-family:Calibri;
                                    panose-1:2 15 5 2 2 2 4 3 2 4;}
                                @font-face
                                    {font-family:Tahoma;
                                    panose-1:2 11 6 4 3 5 4 4 2 4;} 
                                    p.fuente-mail,span.fuente-mail,strong.fuente-mail,span.fuente-mail{font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;}
                                    .imagen-logo{float: right;width: 42%;margin-top: 2%;}
                        </style>  
                     </head> 

                     <body> 
                     <div>
                      <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Dear ".clean_string($_SESSION['nombre2']).",</p> 
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Thank you for contacting us.</p>    <br/>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Our team of professionals have received your inquire and will be in contact with you shortly.</p>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>As one of the leaders in resolving legal issues for international clients, Carbray is proud to represent you in your case, working with you to achieve the most positive outcome.</p>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Thank you for choosing us, and a warm welcome from us all.</p>
<p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Best regards,</p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Name: ".clean_string($_SESSION['nombre2'])." </p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Email Address: ".clean_string($_SESSION['email2'])." </p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Phone: ".clean_string($_SESSION['phone2'])."</p>
                    <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Message: ".clean_string($_SESSION['mensaje2'])."</p>
                     </div>
                     <div> <img class='imagen-logo' style='float: right;width: 42%;margin-top: 2%;' src='http://www.carbray.es/landing_carbray/english/img/logocarbray.png'/></div>
                        <div style='float:left;    width: 50%!important;'>         <div style='float:left'><br/><br/><strong class='fuente-mail' style='<font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'>Barcelona</strong><br/><span style='font-size:12px' class='fuente-mail'>Ronda Sant Pere, 33 Ppal. 3ª y 4ª,<br/>08010 | Tlf.  +34 93 488 09 72</span></div>
                         <div style='float:left;margin-top: 7.5%;padding-left: 4%;'><strong class='fuente-mail'>Madrid Office</strong> <br/><span style='font-size:12px
                         ;font-family:'Calibri','sans-serif';color:#1F497D;' class='fuente-mail'>Paseo de la Castellana, 18 Planta 7ª,<br/>28046 | Tlf.  +34 91 794 28 10</span></div></div>

                         <p class='fuente-mail' style='font-size:13.0pt;font-family:'Calibri','sans-serif';color:#1F497D;'><strong class='fuente-mail'>Disclaimer:</strong> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Your must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient.    </p>
</div>
                     </body> 
                 </html>";










            // create email headers

            $headers2 = "From: " .$_SESSION['email2']. "\r\n";
$headers2 .= 'Bcc:[email protected]' . "\r\n";
$headerscliente3 .= "From: Info Carbray <[email protected]>\r\n". 'X-Mailer: PHP/' . phpversion();

            @mail($email_to2, $email_subject2, $email_message4, $headers2);
            @mail($_SESSION['email2'], $email_subject_client3,     $email_message3, $headerscliente3);              



            /*Message sent! (change the text below as you wish)*/
            header('Location: http://www.carbray.es/landing_carbray/en/thanks.php'); 

             /*End Message Sent*/

            }else
            {

            }
?>
<?php
// Composer's auto-loading functionality
require "vendor/autoload.php";

use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;

$nombreAplicacion = "PhpSheet";
$direccionCorreo = "[email protected]";
$idCliente = "3a5bbd2c9ada9a0f85e8fc1516157400c754d6fa";

// Nombre del SpreadSheet creada
$nombreSpreahSheet = "Php Sheet volcado";
// Nombre de hoja de cálculo
$hojaCalculo = "Hoja 2";

$scope = array('https://spreadsheets.google.com/feeds');

// Inicializamos Google Client
$client = new Google_Client();
$client->setApplicationName($nombreAplicacion);
$client->setClientId($idCliente);

// credenciales, scope y archivo p12. Agregar el correcto Path al archivo p12
$cred = new Google_Auth_AssertionCredentials(
 $direccionCorreo,
 $scope,
 file_get_contents('PhpSheet-3a5bbd2c9ada.p12')
);

$client->setAssertionCredentials($cred);

// si expiro el access token generamos otro
if($client->isAccessTokenExpired()) {
 $client->getAuth()->refreshTokenWithAssertion($cred);
}

// Obtenemos el access token
$obj_token = json_decode($client->getAccessToken());
$accessToken = $obj_token->access_token;

// Inicializamos google-spreadsheet-client
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);

//Obtenemos los Spreadsheets disponibles para las credenciales actuales
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();

// Obtenemos la spreadsheet por su nombre
$spreadsheet = $spreadsheetFeed->getByTitle($nombreSpreahSheet);

// Obtenemos las hojas de cálculo de la spreadsheet obetenida
$worksheetFeed = $spreadsheet->getWorksheets();

// Obtenemos la hoja de cálculo por su nombre
$worksheet = $worksheetFeed->getByTitle($hojaCalculo);
$listFeed = $worksheet->getListFeed();

if(!empty($_SESSION['nombre'])&&!empty($_SESSION['gclid'])) {
$dataAgregar = array('gclid' => $_SESSION['gclid'],
   'nombre' => $_SESSION['nombre'],
 'email' => $_SESSION['email'],
 'telefono' =>"'" .$_SESSION['phone'],
 'mensaje' => $_SESSION['mensaje'],
 'landing' =>  $landingP
 );
 $listFeed->insert($dataAgregar);
}
if(!empty($_SESSION['nombre2'])&&!empty($_SESSION['gclid2'])) {
  $dataAgregar2 = array('gclid' => $_SESSION['gclid2'],
'nombre' => $_SESSION['nombre2'],
 'email' => $_SESSION['email2'],
 'telefono' =>"'" .$_SESSION['phone2'],
 'mensaje' => $_SESSION['mensaje2'],
 'landing' =>  $landingP2
 );
 $listFeed->insert($dataAgregar2);
}    
?>  

    </div>


</body>

</html>
6
  • Podría ser los permisos de los archivos... el 27 oct. 2016 a las 9:28
  • Porque no usas un plugin si tu sitio es wordpress el 27 oct. 2016 a las 9:31
  • Hola Marc, el plugin no lo utilizo porque tengo un php de google apscript que me hace una cosa y con ningun plugin me funciona el php ya que no hay sitio donde ponerlo
    – AitorUdabe
    el 27 oct. 2016 a las 9:32
  • 1
    Hola @aldanux he puesto el codigo html que iria en una pagina en wordpress y el php es un archivo php que esta en la raiz de wordpress, teoricamente deberia de funcionar verdad?
    – AitorUdabe
    el 27 oct. 2016 a las 9:39
  • Solucionado, me faltaba un ; en una linea, gracias
    – AitorUdabe
    el 27 oct. 2016 a las 9:50

2 respuestas 2

1

Hace muy poco estuve armando unos formularios PHP personalizados para WordPress. Tiene sus vueltas. Lo documenté en algunos artículos. Te paso los links. Avisame si necesitás más información:

Hay algunas partes de los artículos que quizá no las necesites. Saludos!

2
  • Gracias a los que habeis contestado, el problema de contact form 7 que lo he utilizado es el siguiente, yo utilizo composer para realizar una cosa con google sheet una vez el usuario le da al boton enviar, con contactform7 no lo puedo realizar o por lo menos no se como hacerlo.
    – AitorUdabe
    el 28 oct. 2016 a las 9:39
  • Creo que tu comentarios es para la otra pregunta. Fijate los artículos que te pasé, seguro te van a servir. Saludos
    – jpussacq
    el 28 oct. 2016 a las 12:05
0

Ya que estás utilizando WordPress te recomiendo no inventar la pólvora. Éste plugin tiene todo y seguramente más de lo que necesitas para crear formularios de forma muy sencilla:

Su página oficial dice:

"Formulario de contacto 7 puede gestionar múltiples formularios de contacto, además, puedes personalizar el formulario y el contenido de los correos electrónicos de manera sencilla mediante un simple marcado. El formulario soporta envíos por Ajax, CAPTCHA, filtrado de spam de Akismet y mucho más."

https://es.wordpress.org/plugins/contact-form-7/

Suerte

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.