943,682 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1874
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 16th, 2007
0

Newbie seeks urgent help

Expand Post »
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
Luc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luc is offline Offline
11 posts
since Jul 2007
Jul 16th, 2007
0

Re: Newbie seeks urgent help

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,757 posts
since May 2007
Jul 16th, 2007
0

Re: Newbie seeks urgent help

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";
}
?>
Luc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luc is offline Offline
11 posts
since Jul 2007
Jul 16th, 2007
0

Re: Newbie seeks urgent help

Yes, your first post did not show any code to check for those entries and went straight to the mail() statement.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,757 posts
since May 2007
Jul 17th, 2007
0

Re: Newbie seeks urgent help

Yeah, quick copy and paste lol... anyways it doesn't work, meaning i still get nothing in my mailbox.
Luc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luc is offline Offline
11 posts
since Jul 2007
Jul 17th, 2007
0

Re: Newbie seeks urgent help

Post the entire piece of code and use the code tags.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,757 posts
since May 2007
Jul 17th, 2007
0

Re: Newbie seeks urgent help

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)
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is online now Online
16,501 posts
since Apr 2005
Jul 17th, 2007
0

Re: Newbie seeks urgent help

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.

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007
Jul 17th, 2007
0

Re: Newbie seeks urgent help

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
Luc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luc is offline Offline
11 posts
since Jul 2007
Jul 17th, 2007
0

Re: Newbie seeks urgent help

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.
Luc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Luc is offline Offline
11 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Previewing PHP frameset files in browser
Next Thread in PHP Forum Timeline: FTP Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC