script execution
Moderator: General Moderators
script execution
i would like the below script first to check if an emai field is empty. and i only want the script to execute further if the field is not empty. this is working.
then i would like the script to check the format, and only continue exectuing when the format is a valid email address format.
however whether the format is correct or not, my script just continues to send the mail to an invalid email address.
any ideas on what i need to do.
<?php
if ($email=="")echo 'whatever';
else {
function emailcheck($intext) {
$theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = 'whatever'; }
echo("$isamatch<br>\n");
}
emailcheck("$email");
$from = "whatever> ";
$subject = "whatever";
$message = 'whatever'
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from."\r\n";
mail($email, $subject, $message, $headers);
echo 'whatever';
?>
thanks
then i would like the script to check the format, and only continue exectuing when the format is a valid email address format.
however whether the format is correct or not, my script just continues to send the mail to an invalid email address.
any ideas on what i need to do.
<?php
if ($email=="")echo 'whatever';
else {
function emailcheck($intext) {
$theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = 'whatever'; }
echo("$isamatch<br>\n");
}
emailcheck("$email");
$from = "whatever> ";
$subject = "whatever";
$message = 'whatever'
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from."\r\n";
mail($email, $subject, $message, $headers);
echo 'whatever';
?>
thanks
Hey i don't know but you can always out a small js script in your head
Code: Select all
function checkform(name of your form)
{
if (!(/^\w+(ї\.-]?\w+)*@\w+(ї\.-]?\w+)*(\.\w{2,3})+$/.test(name_of_your_form.name_of_your_field.value))){
alert("msg output.")
return (false)
}
return (true)
}Ok well i'm a noob but you could try that..
use this as an exemple
with the "!" you can chek when a function "is not equals to"
dunno if i helped..
but hey i tried
cheers
use this as an exemple
Code: Select all
if (!$checkmail) {
//include the code you want to execute when the email is WRONG
exit;
}else{
//include the code when the email is good
}dunno if i helped..
but hey i tried
cheers
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
reply
try this
and i'm assuming your using a form to send the mail, this script is just to process the form
i'm pretty sure this will work, but i can't rey it b/c im in school right no
and i'm assuming your using a form to send the mail, this script is just to process the form
Code: Select all
<?php
function emailcheck($intext) {
$theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
if ($theresults) { $isamatch = ""; } else { $isamatch = 'whatever'; }
echo("$isamatch<br>\n");
}
if (!isset($_POST['email'])){//checks to see if the form field 'email' is not set
echo 'please enter a email address';
exit;
}
elseif(emailcheck("$email")){//uses your function to see if its a valid email address
exit;
}
else{//if everything is ok it sends the mail
$from = "whatever> ";
$subject = "whatever";
$message = 'whatever';
// Added a ; --JAM
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from."\r\n";
mail($email, $subject, $message, $headers);
echo 'whatever';
}
?>- Saethyr
- Forum Contributor
- Posts: 182
- Joined: Thu Sep 25, 2003 9:21 am
- Location: Wichita, Kansas USA
- Contact:
try this. changed it to what I think you were trying to do.
Saethyr
Code: Select all
function ValidateMail($Email) {
$result = array();
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
$result[0]="TRUE";
$result[1]="FALSE";
return $result;
}
$newEmail = ValidateMail($email);
if ($newEmail == "FALSE")
{
echo "email is not valid!";
exit;
}
else
{
$from = "fake@email.com";
$subject = "whatever";
$message = 'whatever';
// Added a ; --JAM
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from."\r\n";
mail($email, $subject, $message, $headers);
echo 'Email Sent To $email!';
}Just adding some input about redirects:
By using the header() function you can send the user to somewhere else. So if we take Saethyr's example above;
Code: Select all
header("Location: http://www.example.com/");Code: Select all
/// cut...
if ($newEmail == "FALSE")
{
header("Location: bad_email.php"); // ...example
exit;
}
// cut...script execution
still not getting there. it still goes on with sending the mail if the email format is not correct.
thanks for trying though.
thanks for trying though.
btw the code you posted isn't correct
cheers
replace withgecko wrote: however whether the format is correct or not, my script just continues to send the mail to an invalid email address.
any ideas on what i need to do.Code: Select all
if ($email=="")echo 'whatever';//this isn't good else {
Code: Select all
if ($email==""){ //see the opening bracket
echo "whatever";
}else{
//whatever code you wantCode: Select all
<?php
$email = 'foo@example.com';
function ValidateMail($email) {
if (eregi("^[\w.-]+@[\w.-]+\.(com|net|org|edu|mil|gov|gob|info|tv|biz) +(\.[A-Za-z]{2}|\s*)$", $email)) {
/*
^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$
...might also be worth looking at as expression (?)
*/
return 1;
} else {
return 0;
} }
// validate $email...
$newEmail = ValidateMail($email);
// act upon result...
// forgot the !
if (!$newEmail) {
header("Location: bad_page.php");
exit;
} else {
$from = "fake@email.com";
$subject = "whatever";
$message = "whatever";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$from."\r\n";
mail($email, $subject, $message, $headers);
echo 'Email Sent To '.$email.'!';
}
?>
Last edited by JAM on Thu Dec 18, 2003 3:37 pm, edited 2 times in total.
script execution
jam i tried your script.
the result = Email Sent To ff!
this happened when i filled in ff in the form, so it is still accepting a non valid email address.
thanks anyway
the result = Email Sent To ff!
this happened when i filled in ff in the form, so it is still accepting a non valid email address.
thanks anyway
script execution
thanks jam i noticed the same. it is working fine now.
thanks a lot for your help
thanks a lot for your help