Jump to content

Email Verified


Kristoff1875

Recommended Posts

Don't shoot me please!!!

 

I've tried about 50 different ways of doing this but still can't get the sender to check whether the email is of the right format ie (name@email.com), I don't even care if the email is real as long as it's in email format.

 

Here is my code:

 

<?php
$myemail = "****";
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$dobday = $_POST['dobday'] ;
$dobmonth = $_POST['dobmonth'] ;
$dobyear = $_POST['dobyear'] ;
$town = $_POST['town'] ;

if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
header("Location: error.php");
}
else
{
$message = "Someone has filled out Mailing List Form:\n
\n
Name: $name\n
Email: $email\n
Phone: $phone\n
D.O.B: $dobday $dobmonth $dobyear\n
Town: $town\n";

mail ($myemail, "Mailing List Form", $message, "From: $email");

header("Location: formsubmitted.php");
}
?> 

 

Any help appreciated!

Link to comment
Share on other sites

I know, that is the only attempt on there at the moment as everything else i've tried just brings up an error?

 

EDIT:

 

Just tried this again:

 

<?php
$myemail = "";
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$dobday = $_POST['dobday'] ;
$dobmonth = $_POST['dobmonth'] ;
$dobyear = $_POST['dobyear'] ;
$town = $_POST['town'] ;

function valid_email($email) {
  // check an email address is possibly valid
  if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) {
    return true;
  } else {
    return false;
  }
}

if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
header("Location: error.php");
}
else
{
$message = "Someone has filled out Mailing List Form:\n
\n
Name: $name\n
Email: $email\n
Phone: $phone\n
D.O.B: $dob\n
Town: $town\n";

mail ($myemail, "Mailing List Form", $message, "From: $email");

header("Location: formsubmitted.php");
}
?> 

 

And it works, but it allowed "test" as the email  :confused:

Link to comment
Share on other sites

This is the code i used when i made a registration page, it checked length first which can easily be removed. Mod to your needs. escape_data() was a function i made that made sure it was clean to be inserted into myself database..

 

	if (strlen($_POST['email']) <= 40) {
	if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
		$e = escape_data($_POST['email']);
	} else {
		$e = FALSE;
		echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>';
	}
} else {
	$e = FALSE;
	echo '<p>The email address you provided exceeds maximum length of 40 letters</p>';
} 

Link to comment
Share on other sites

Hi, thanks for the assistance!

 

This is my full code from the php sender:

 

<?php
$myemail = "info@******.com";
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$dobday = $_POST['dobday'] ;
$dobmonth = $_POST['dobmonth'] ;
$dobyear = $_POST['dobyear'] ;
$town = $_POST['town'] ;

if(preg_match("~[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}~i", $email))
{
  return TRUE;
}
else
{
  echo FALSE;
}

if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
header("Location: error.php");
}
else
{
$message = "Someone has filled out The Honey Club Mailing List Form:\n
\n
Name: $name\n
Email: $email\n
Phone: $phone\n
D.O.B: $dob\n
Town: $town\n";

mail ($myemail, "Mailing List Form", $message, "From: $email");

header("Location: formsubmitted.php");
}
?> 

 

It goes to formsubmitted.php and the email is sent, but even if the email is just "test" it still sends fine  :shrug:

 

Thanks again!

Link to comment
Share on other sites

It goes to formsubmitted.php and the email is sent, but even if the email is just "test" it still sends fine  :shrug:

 

Lets run through your code with the email set to "test".

 

if(preg_match("~[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}~i", $email))
{
  return TRUE;
}
else
{
  echo FALSE;
}

 

If the email "test" matches that pattern, the page execution is stopped (due to return) with a value of TRUE. In all likelihood, that is not what you want to be happening. If the email address matches the pattern (ie, is what you want to be considered a valid email address) then we want to allow execution to continue processing! 

 

Since our email "test" does not match the pattern, we are moved to the else block which echoes FALSE (an empty string, nothing). There is nothing here stopping the execution of the page so we go down to the next if block.

 

if (empty($name) || empty($email) || empty($phone) || empty($dobday) || empty($dobmonth) || empty($dobyear) || empty($town)){
header("Location: error.php");
}
else
{
$message = "Someone has filled out The Honey Club Mailing List Form:\n
\n
Name: $name\n
Email: $email\n
Phone: $phone\n
D.O.B: $dob\n
Town: $town\n";

mail ($myemail, "Mailing List Form", $message, "From: $email");

header("Location: formsubmitted.php");
}

 

Lets assume all of the other values have been provided and don't constitute being "empty", we know that email isn't empty (remember, it is "test").  Because none of them are "empty" again we are moved to the else block.  This one sends the email.

 

In conclusion, if a valid email is provided (according to your regular expression) then execution of the page is stopped. If an invalid email is provided and one or more of the other values is "empty" then the page is redirected to error.php. If an invalid email is provided and all of the other values are not "empty" then, and only then, the email is sent.

 

Can you see the problem?

 

 

Link to comment
Share on other sites

I think I see that because even if it's false, it's still submitting the form as long as the others are all filled in, however, I did try making the false part go to the error page, which still didnt work.

 

The only thing I can think is that there should be a check as well as the checks to make sure the fields are filled in, that checks whether preg_match is true or false?

 

No idea how I should do that so any advice is greatly appreciated!

 

Thanks for the help!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.