| | |
Mail () function code error need help to check
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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
send.php
PHP Syntax (Toggle Plain Text)
<?php $to=stripslashes($_POST['to']); if($to == '0'){ $to='mail1@mail.com'; @mail($to, $subject, $message, $headers); }else { $to='mail2@mail.com'; @mail($to, $subject, $message, $headers); } $from=$_POST['from']; $subject=$_POST['subject']; $ip=$_POST['ip']; $phone=$_POST['phone']; $message=$_POST['problem']; $fields = array(); $fields{"from"} = "Name"; $fields{"email"} = "Email"; $fields{"phone"} = "Phone Ext"; $fields{"ip"}="IP Address"; $fields{"problem"} = "Request"; 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>";} else { 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>";} else { if($subject== '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Subject, please go back and try again!!')</script>";} else { } } } $message = "Here is the following detail:\n\n"; foreach($fields as $a => $b){ $message.= sprintf("%20s: %s\n",$b,$_POST[$a]); } $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $data = chunk_split(base64_encode($data)); $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; } $ok = @mail($to, $subject, $message, $headers); if ($ok) { 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>"; } else { echo "<p>SYSTEM BUSY! Mail Could not be Sent ! Please Try it Later!</p>"; } ?>
Hi there,
Try instead of the check
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(); }
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
•
•
Join Date: Jan 2008
Posts: 57
Reputation:
Solved Threads: 5
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;
Hope this will help you, if it did, add it to my reputation. Thanks
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)
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>";} else { 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>";} else { if($subject== '') {echo "<script langauge=\"javascript\">alert('Mail not Sent,You have not entered a Subject, please go back and try again!!')</script>";} else { $ok = @mail($to, $subject, $message, $headers); // because the system will send mail even after showing the alert // messages to the user. you should write the mail code inside the // innermost else block. } } }
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---------------------------
" A man is known by his level of Determinism "
--------------------------------------------------------
"Some cause happiness where ever they go, others whenever They go"
--------------------------XIII---------------------------
![]() |
Similar Threads
- Mail Server run in local host but cant use Mail() Function (PHP)
- how to configure smtp for mail function? (PHP)
- mail function problem (PHP)
- Mail Function syntax error (PHP)
- Problems with PHP mail function. (PHP)
- Stuck on Mail() Function (PHP)
Other Threads in the PHP Forum
- Previous Thread: One Delete Button For Many Records
- Next Thread: Mysql Problem
Views: 423 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube





