Jump to content

[SOLVED] Newbie seeking desperately help with php based form


Luc

Recommended Posts

Hi folks, first post here :-)

 

I'm new to php and mangled my fist php driven form together but upon sending, i get directed to the success page but nothing gets delivered in my mailbox.

 

Here's the code:

<?

    // set your own preferences here

#############################################################

// Your email address

$youremail =  'my adress';

// Your web site title (John Doe's Site)

$websitetitle =  'my title';

// Path to "thanks for the message" page

$thankyoupage =  'http://www......../Contact_success1.php';

// Send notification to sender (use false if not required)

$sendnotification = true;

  // Continue with your error checking, output of form, et cetera.

$contact_form_action = $_SERVER['PHP_SELF'];

if ((isset($_POST["sendcontact"])) && ($_POST["sendcontact"] == "contactsent")) {

$contacter_form_error = array();

if (empty($_POST['empresa_name'])){

$contacter_form_error[] = 'favor preencher nome da empresa';

}

if (empty($_POST['contato_name'])){

$contacter_form_error[] = 'favor preencher nome do contato';

}

if (empty($_POST['fone'])){

$contacter_form_error[] = 'favor preencher número do telefone';

}

if (empty($_POST['contato_email'])){

$contacter_form_error[] = 'favor preencher seu e-mail';

}

if (empty($_POST['produto'])){

$contacter_form_error[] = 'favor preencher o produto';

}

if (empty($_POST['origem'])){

$contacter_form_error[] = 'favor preencher origem';

}

if (empty($_POST['destino'])){

$contacter_form_error[] = 'favor preencher destino';

}

if (empty($_POST['quantidade'])){

$contacter_form_error[] = 'favor preencher quantidade';

}

if (empty($_POST['peso'])){

$contacter_form_error[] = 'favor preencher peso';

}

if (empty($_POST['comprimento'])){

$contacter_form_error[] = 'favor preencher comprimento';

}

if (empty($_POST['altura'])){

$contacter_form_error[] = 'favor preencher altura';

}

if (empty($_POST['largura'])){

$contacter_form_error[] = 'favor preencher largura';

}

else {

$empresa_name = stripslashes($_POST['empresa_name']);

$contato_email = stripslashes($_POST['contato_email']);

 

    $body =<<<EOB

Empresa: $_POST[empresa_name]

Contato: $_POST[contato_name]

Fone: $_POST[fone]

Fax: $_POST[fax]

Email: $_POST

Produto: $_POST[produto]

Origem: $_POST[origem]

Destino: $_POST[destino]

Quantidade: $_POST[quantidade]

Peso: $_POST[peso]

Comprimento: $_POST[comprimento]

Altura: $_POST[altura]

Largura: $_POST[largura]

EOB;

$subjectline = "$websitetitle | Orçamento de empresa";

 

 

   

 

if($sendnotification == true) {

$notification_message = "Obrigado por nos contatar, $contato_name. Recebemos sua mensagem e entraremos em contato em breve";

$notification_subject = "Obrigado por sua mensagem para $websitetitle.";

mail($contato_email,$subjectline,$body);

mail($contato_email, $notification_subject, $notification_message, "From: $youremail");

}

header("Location:$thankyoupage");

}

}

?>

 

Follows html tags, followed by:

<?

// Print form field errors if present

if (count($contacter_form_error)>0){

print '<p id="bottom"><strong>Algo está errado:</strong></p>'."\n";

print '<ul>'."\n";

foreach($contacter_form_error as $form_err) {

print "<li class=\"error\">$form_err</li>\n";

}

print '</ul>'."\n";

}

?>

<form method="post" id="contactform" action="<? print $contact_form_action; ?>">

<div>

<p>Todos os campos obrigatórios são marcados com asteriscos (<span class="required">*</span>).</p>

<fieldset>

<legend>Seus Dados</legend>

<label for="empresa_name">Empresa <span class="required">*</span></label>

<br />

<input type="text" id="empresa_name" name="empresa_name" size="30" value="<? print $empresa_name; ?>" />

<br />

<label for="contato_name">Contato <span class="required">*</span></label>

<br />

<input type="text" id="contato_name" name="contato_name" size="30" value="<? print $contato_name; ?>" />

<br />

<label for="fone">Número do telefone <span class="required">*</span></label>

<br />

<input type="text" id="fone" name="fone" size="30" value="<? print $fone; ?>" />

<br />

<label for="fax">Fax</label>

<br />

<input type="fax" id="fax" name="fax" size="30" value="<? print $fax; ?>" />

<br />

<label for="contato_email">E-mail <span class="required">*</span></label>

<br />

<input type="contato_email" id="contato_email" name="contato_email" size="30" value="<? print $contato_email; ?>" />

<br />

<label for="produto">Produto <span class="required">*</span></label>

<br />

<input type="produto" id="produto" name="produto" size="30" value="<? print $produto; ?>" />

<br />

<label for="origem">Origem <span class="required">*</span></label>

<br />

<input type="origem" id="origem" name="origem" size="30" value="<? print $origem ?>" />

<br />

<label for="destino">Destino <span class="required">*</span></label>

<br />

<input type="destino" id="destino" name="destino" size="30" value="<? print $destino; ?>" />

<br />

<label for="quantidade">Quantidade <span class="required">*</span></label>

<br />

<input type="quantidade" id="quantidade" name="quantidade" size="30" value="<? print $quantidade; ?>" />

<br />

<label for="peso">Peso <span class="required">*</span></label>

<br />

<input type="peso" id="peso" name="peso" size="30" value="<? print $peso; ?>" />

<br />

<label for="comprimento">Comprimento <span class="required">*</span></label>

<br />

<input type="comprimento" id="comprimento" name="comprimento" size="30" value="<? print $comprimento; ?>" />

<br />

<label for="altura">Altura <span class="required">*</span></label>

<br />

<input type="altura" id="altura" name="altura" size="30" value="<? print $altura; ?>" />

<br />

<label for="largura">Largura <span class="required">*</span></label>

<br />

<input type="largura" id="largura" name="largura" size="30" value="<? print $largura; ?>" />

<br />

</fieldset>

<input type="hidden" name="sendcontact" value="contactsent" />

<input type="submit" value="Enviar" />

</div>

</form>

 

As i'm on a deadline, help from the gurus is appraciated!!!!

 

TIA

 

Luc

 

Link to comment
Share on other sites

Hi Richard,

 

tnx for answering my question.

 

I've put your solution before the mailfunction like this:

 

$tosend="Forename: $contato_name\n Email: $contato_email\n";

 

But still no go ...

 

Is there something i'm missing in my "being stupid" mode?

Link to comment
Share on other sites

Just a hunch, may not be it...but if everything else works but nothing gets mailed I think the logic for the sending of the email is a bit cockeyed. Follow me on this:

 

1. you have a variable set // Send notification to sender (use false if not required)

$sendnotification = true;

 

2. then you check against that before sending. Since the variable appears to be always set to 'true' I don't know why you need to 'if' it before sending. Since that variable is hard-coded (meaning the value isn't set by a form field, for example) then why 'if' it?

 

Just for fun, take the 'if' statement away from the mail functions and see what happens. You can just comment them out using //'s

Link to comment
Share on other sites

Great, it works now but i'm confronted with a new problem:

 

the data get's delivered, except the email from the sender:

Empresa: TEST

Contato: LUC

Fone: 989

Fax: 090

Email:

Produto: TEST

Origem: TEST

Destino: TEST

Quantidade: TEST

Peso: TEST

Comprimento: TEST

Altura: TEST

Largura: TEST

 

Also the notification mail to the sender leaves his name out:

Obrigado por nos contatar, (here should be his name). Recebemos sua mensagem e entraremos em contato em breve

 

TIA

 

Link to comment
Share on other sites

flowingwindrider: that gives me following parse error if i change that:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

 

that's why i left the " ' " out.

Link to comment
Share on other sites

it's called contato_name and it's set up like this in the $notification_message:

$notification_message = "Obrigado por nos contatar, $contato_name. Recebemos sua mensagem e entraremos em contato em breve";

 

In the meanwhile i stumbled upon something else:

when i receive te email, the from field filles in the name of my server instead of the email from the sender of the form. Is there a special line of code i need to use to achieve that effect?

 

I now have:

mail($contato_email,$subjectline,$body);

mail($contato_email, $notification_subject, $notification_message, "From: $youremail");

 

so i thought that $contato_email would show the email in the from field of the message?

Link to comment
Share on other sites

Well i solved 1 problem:

 

changing mail($contato_email,$subjectline,$body); to mail($contato_email,$subjectline,$body, "From: $contato_email"); made teh sendes adress appaer in the from field  ;D

 

The only problem left is with the notification as described above :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.