Newbie seeks urgent help

Thread Solved

Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Newbie seeks urgent help

 
0
  #1
Jul 16th, 2007
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("Locationthankyoupage");
}
}
?>

Any help is appreciated

TIA

Luc
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Newbie seeks urgent help

 
0
  #2
Jul 16th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Re: Newbie seeks urgent help

 
0
  #3
Jul 16th, 2007
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";
}
?>
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Newbie seeks urgent help

 
0
  #4
Jul 16th, 2007
Yes, your first post did not show any code to check for those entries and went straight to the mail() statement.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Re: Newbie seeks urgent help

 
0
  #5
Jul 17th, 2007
Yeah, quick copy and paste lol... anyways it doesn't work, meaning i still get nothing in my mailbox.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Newbie seeks urgent help

 
0
  #6
Jul 17th, 2007
Post the entire piece of code and use the code tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,221
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 538
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Newbie seeks urgent help

 
0
  #7
Jul 17th, 2007
yes, also how do you have the mailserver set up? (you have got a mail server set up, right? youd be amazed the number of n00bs who just expect PHP to be able to magically send mail)
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: Newbie seeks urgent help

 
0
  #8
Jul 17th, 2007
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.

  1. <?php
  2. if(isset($_POST['your_submit_button_name_here'])) {
  3.  
  4.  
  5. $from = $_POST['form_from'];
  6. $subject = $_POST['form_message'];
  7. $message = $_POST['form_subject'];
  8.  
  9. if(strlen($from) > 0 AND strlen($subject) > 0 AND strlen($message) > 0) {
  10. if(emailUser($from, $subject, $message))
  11. echo "Email Sent";
  12. else
  13. echo "Email Not Sent";
  14. }
  15.  
  16.  
  17. function emailUser ($from, $subject, $message) {
  18.  
  19. $to = 'you@youremail.com';
  20. $headers = "From: " . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
  21. return mail ($to, $subject, $message, $headers);
  22. }
  23.  
  24. } else {
  25. ?>
  26.  
  27.  
  28. <!-- Do your HTML Here -->
  29.  
  30.  
  31.  
  32. <?php
  33. }
  34. ?>


Cheers.
Enjoy.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Re: Newbie seeks urgent help

 
0
  #9
Jul 17th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Re: Newbie seeks urgent help

 
0
  #10
Jul 17th, 2007
The blank email is solved:
Changing Email: $_POST[email]

to

Email: $_POST[contato_email]

did the trick.

But i'm stumped why 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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC