943,614 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 695
  • PHP RSS
Jun 26th, 2009
-1

Mail () function code error need help to check

Expand Post »
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
PHP Syntax (Toggle Plain Text)
  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. ?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
gingank is offline Offline
108 posts
since Jun 2009
Jun 26th, 2009
0

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

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.
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009
Jun 27th, 2009
0

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

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;

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
emarshah is offline Offline
61 posts
since Jan 2008

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: One Delete Button For Many Records
Next Thread in PHP Forum Timeline: Mysql Problem





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


Follow us on Twitter


© 2011 DaniWeb® LLC