| | |
Newbie seeks urgent help
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2007
Posts: 11
Reputation:
Solved Threads: 0
Hi folks,
just registered here in the hope to get some help. I'm new to PHP and have following problem: a simple form used to get the field inputs into my email box. But although i get a "successful" page upon sending, nothing drops in my mailbox.
Here's the full code:
<?
// set your own preferences here
#############################################################
// Your email address
$youremail = 'my adres';
// Your web site title (John Doe's Site)
$websitetitle = 'website title';
// Path to "thanks for the message" page
$thankyoupage = '....../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[email]
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";
mail($contato_email, $subjectline, $body);
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, $notification_subject, $notification_message, "From: $youremail");;
}
header("Location
thankyoupage");
}
}
?>
Any help is appreciated
TIA
Luc
just registered here in the hope to get some help. I'm new to PHP and have following problem: a simple form used to get the field inputs into my email box. But although i get a "successful" page upon sending, nothing drops in my mailbox.
Here's the full code:
<?
// set your own preferences here
#############################################################
// Your email address
$youremail = 'my adres';
// Your web site title (John Doe's Site)
$websitetitle = 'website title';
// Path to "thanks for the message" page
$thankyoupage = '....../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[email]
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";
mail($contato_email, $subjectline, $body);
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, $notification_subject, $notification_message, "From: $youremail");;
}
header("Location
thankyoupage");}
}
?>
Any help is appreciated
TIA
Luc
I don't see anywhere that your code checks to see if there is anything in the error array and display it if needed. It just goes on to attempt to send the mail and it also doesn't check the return value of the mail function. Make sure you are actually displaying any errors in your error message array and you may want to try to echo your mail parameters prior to sending, to make sure those look ok to you. Capture the return value from mail() and check that as well.
•
•
Join Date: Jul 2007
Posts: 11
Reputation:
Solved Threads: 0
ezzaral, is this the error checking you refer to?
<?
// 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";
}
?>
<?
// 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";
}
?>
The following is the necessary code to store, check that no info was empty and email the user.
You will need to change the $to variable to suit your needs.
You will also need to make <input name="form_from"> for the Text Box that stores the users email address
And the same need applied to the subject and message input boxes.
Cheers.
Enjoy.
You will need to change the $to variable to suit your needs.
You will also need to make <input name="form_from"> for the Text Box that stores the users email address
And the same need applied to the subject and message input boxes.
php Syntax (Toggle Plain Text)
<?php if(isset($_POST['your_submit_button_name_here'])) { $from = $_POST['form_from']; $subject = $_POST['form_message']; $message = $_POST['form_subject']; if(strlen($from) > 0 AND strlen($subject) > 0 AND strlen($message) > 0) { if(emailUser($from, $subject, $message)) echo "Email Sent"; else echo "Email Not Sent"; } function emailUser ($from, $subject, $message) { $to = 'you@youremail.com'; $headers = "From: " . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); return mail ($to, $subject, $message, $headers); } } else { ?> <!-- Do your HTML Here --> <?php } ?>
Cheers.
Enjoy.
GardCMS :: Open Source CMS :: Gardcms.org
•
•
Join Date: Jul 2007
Posts: 11
Reputation:
Solved Threads: 0
Hi folks,
about the server: i used my providers' one since it supports php fully.
But it's resolved now:
I had a variable set // Send notification to sender (use false if not required)
$sendnotification = true;
then I checked against that before sending. Since the variable appears to be always set to 'true' no need to 'if' it before sending, right? Since that variable is hard-coded (meaning the value isn't set by a form field, for example) then why 'if' it?
Taking the 'if' statement away from the mail functions worked :-)
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 brev
about the server: i used my providers' one since it supports php fully.
But it's resolved now:
I had a variable set // Send notification to sender (use false if not required)
$sendnotification = true;
then I checked against that before sending. Since the variable appears to be always set to 'true' no need to 'if' it before sending, right? Since that variable is hard-coded (meaning the value isn't set by a form field, for example) then why 'if' it?
Taking the 'if' statement away from the mail functions worked :-)
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 brev
![]() |
Other Threads in the PHP Forum
- Previous Thread: Previewing PHP frameset files in browser
- Next Thread: FTP Help
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube






