Make contact form in html in wordpress

1

I have a contact form in html on a wordpress page, the contact.php that is the action of the form, is in the root but when I give the send button I get an error 500, why is this error?

the contact.php that is where we send the mail etc, must be in a specific place?

HTML code that I have on a page:

<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>

PHP code that sends the mail:          

<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>
    
asked by AitorUdabe 27.10.2016 в 11:22
source

2 answers

1

I was recently putting together custom PHP forms for WordPress. It has its turns. I documented it in some articles. I pass the links to you. Let me know if you need more information:

There are some parts of the articles that you may not need. Greetings!

    
answered by 27.10.2016 / 16:22
source
0

Since you are using WordPress, I recommend you do not invent gunpowder. This plugin has everything and surely more than you need to create forms in a very simple way:

Your official page says:

  

"Contact Form 7 can manage multiple contact forms, in addition, you can customize the form and the content of the emails in a simple way by means of a simple markup The form supports sending by Ajax, CAPTCHA, spam filtering of Akismet and much more. "

link

Luck

    
answered by 28.10.2016 в 02:34