Mail () function code error need help to check

Reply

Join Date: Jun 2009
Posts: 95
Reputation: gingank is an unknown quantity at this point 
Solved Threads: 0
gingank's Avatar
gingank gingank is offline Offline
Junior Poster in Training

Mail () function code error need help to check

 
-1
  #1
Jun 26th, 2009
Hi guy can anyone help me this code i get the error. It suppose will come out the java script alert first if the use did not fill up the phone number or the subject but it will send the mail also if the user did not fill up the phone number can help me on this

send.php
  1. <?php
  2. $to=stripslashes($_POST['to']);
  3. if($to == '0'){
  4. $to='mail1@mail.com';
  5. @mail($to, $subject, $message, $headers);
  6. }else {
  7. $to='mail2@mail.com';
  8. @mail($to, $subject, $message, $headers);
  9. }
  10. $from=$_POST['from'];
  11. $subject=$_POST['subject'];
  12. $ip=$_POST['ip'];
  13. $phone=$_POST['phone'];
  14. $message=$_POST['problem'];
  15.  
  16.  
  17. $fields = array();
  18. $fields{"from"} = "Name";
  19. $fields{"email"} = "Email";
  20. $fields{"phone"} = "Phone Ext";
  21. $fields{"ip"}="IP Address";
  22. $fields{"problem"} = "Request";
  23.  
  24. if($from == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent, You have not entered a Name, please go back fill up and try again!!')</script>";}
  25. else {
  26. if($phone == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Phone Ext, please go back fill up and try again!!')</script>";}
  27. else {
  28. if($subject== '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Subject, please go back and try again!!')</script>";}
  29. else {
  30. }
  31. }
  32. }
  33.  
  34. $message = "Here is the following detail:\n\n"; foreach($fields as $a => $b){ $message.= sprintf("%20s: %s\n",$b,$_POST[$a]); }
  35.  
  36. $fileatt = $_FILES['fileatt']['tmp_name'];
  37. $fileatt_type = $_FILES['fileatt']['type'];
  38. $fileatt_name = $_FILES['fileatt']['name'];
  39.  
  40. $headers = "From: $from";
  41.  
  42. if (is_uploaded_file($fileatt)) {
  43. $file = fopen($fileatt,'rb');
  44. $data = fread($file,filesize($fileatt));
  45. fclose($file);
  46.  
  47.  
  48. $semi_rand = md5(time());
  49. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  50.  
  51.  
  52. $headers .= "\nMIME-Version: 1.0\n" .
  53. "Content-Type: multipart/mixed;\n" .
  54. " boundary=\"{$mime_boundary}\"";
  55.  
  56.  
  57. $message = "This is a multi-part message in MIME format.\n\n" .
  58. "--{$mime_boundary}\n" .
  59. "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
  60. "Content-Transfer-Encoding: 7bit\n\n" .
  61. $message . "\n\n";
  62.  
  63.  
  64. $data = chunk_split(base64_encode($data));
  65.  
  66.  
  67. $message .= "--{$mime_boundary}\n" .
  68. "Content-Type: {$fileatt_type};\n" .
  69. " name=\"{$fileatt_name}\"\n" .
  70. "Content-Transfer-Encoding: base64\n\n" .
  71. $data . "\n\n" .
  72. "--{$mime_boundary}--\n";
  73. }
  74.  
  75.  
  76.  
  77. $ok = @mail($to, $subject, $message, $headers);
  78. if ($ok) {
  79. echo "<p>Thank you for using the system. Your request have be sent. We will get back to you shortly. Please be patient, thank you !</p>";
  80. } else {
  81. echo "<p>SYSTEM BUSY! Mail Could not be Sent ! Please Try it Later!</p>";
  82. }
  83. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 172
Reputation: Menster is an unknown quantity at this point 
Solved Threads: 22
Menster's Avatar
Menster Menster is offline Offline
Junior Poster

Re: Mail () function code error need help to check

 
0
  #2
Jun 26th, 2009
Hi there,
Try instead of the check $phone == '' , use if (empty($phone) || !isset($phone))
Last edited by peter_budo; Jun 28th, 2009 at 5:15 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: emarshah is an unknown quantity at this point 
Solved Threads: 5
emarshah emarshah is offline Offline
Junior Poster in Training

Re: Mail () function code error need help to check

 
0
  #3
Jun 27th, 2009
Hi,

It sends the mail because you didn't write the else code, you should send the mail in the else block of all the above if's ....
try the following;

  1.  
  2. if($from == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent, You have not entered a Name, please go back fill up and try again!!')</script>";}
  3. else {
  4. if($phone == '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Phone Ext, please go back fill up and try again!!')</script>";}
  5. else {
  6. if($subject== '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Subject, please go back and try again!!')</script>";}
  7. else
  8. {
  9. $ok = @mail($to, $subject, $message, $headers);
  10.  
  11. // because the system will send mail even after showing the alert
  12. // messages to the user. you should write the mail code inside the // innermost else block.
  13. }
  14. }
  15. }

Hope this will help you, if it did, add it to my reputation. Thanks
Last edited by emarshah; Jun 27th, 2009 at 5:33 am.
Syed Ammar Hassan
" A man is known by his level of Determinism "
--------------------------------------------------------
"Some cause happiness where ever they go, others whenever They go"
--------------------------XIII---------------------------
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 423 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC