Jump to content

Help with email validation?


visionx

Recommended Posts

So, im trying to make my job a little easier. lol... I am constantly sending emails to the managers for escalations on calls... So I wrote this so far... (forgive my poor php skills, this is the first thing ive ever made. lol.)

 

It does work so far, but, a friend wants to use it too, and Ive adapted it so he can enter his email address in, but, how can I make it so that it will validate only to send from @specificdomain.com ?

 

Ive tried a few things, and just butchered it. lol....

 

Thanks for any help or tips. :)

 


<?php
//$name = $_POST["email"];
$name = $_POST["name"];
$policynumber = $_POST["policynumber"];
$phonenumber = $_POST["phonenumber"];
$issue = $_POST["issue"];
$purchased = $_POST ["purchased"];
$infocheck  = $_POST ["infocheck"];
$additionalinfo = stripslashes($_POST["additionalinfo"]);

//checkbox value readout
$mailcc = $_POST['sendmetoo'];

$email_to = "[email protected]"; // Who the email is to
$email_from = $_POST['emailfrom']; // Who the email is from
$email_subject = $policynumber.' - '.$issue; // The Subject of the email

//here you can define whatever you want to...
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers .= "To: <".$email_to.">\r\n";
$headers .= "From: ".$email_from."\r\n";

//we control if sendmetoo is checked...
if($mailcc == 'sendtome'){
       $headers .= "Cc: ".$email_from."\r\n";
}
//$headers .= "Bcc: [email protected]\r\n";

$email_message = "Sales Level 2,";
$email_message .= "\n\nPolicy Number: " .$policynumber;
$email_message .= "\nClients Name: " .$name;
$email_message .= "\nPhone Number: " .$phonenumber;
$email_message .= "\nReason(s): " .$issue;
$email_message .= "\nPurchased Already: " .$purchased;
$email_message .= "\nAll info correct?: " .$infocheck;
$email_message .= "\n\nAdditional Information: " .$additionalinfo;
"\n\n\n\n". // Message that the email has in it

//$headers = "From: ".$email_from;

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "<font face=verdana size=2><center>Your message has been sent<br>
to Sales Level 2<br>
Click <a href=\"#\" onclick=\"history.back();\">here</a> to go back</center>";

} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/223967-help-with-email-validation/
Share on other sites

Here is what I have tried so far...

 

First I tried...

 

<?php
//$name = $_POST["email"];
$name = $_POST["name"];
$policynumber = $_POST["policynumber"];
$phonenumber = $_POST["phonenumber"];
$issue = $_POST["issue"];
$purchased = $_POST ["purchased"];
$infocheck  = $_POST ["infocheck"];
$additionalinfo = stripslashes($_POST["additionalinfo"]);

//checkbox value readout
$mailcc = $_POST['sendmetoo'];

$email_to = "[email protected]"; // Who the email is to
$email_from = $_POST['emailfrom']; // Who the email is from
$email_subject = $policynumber.' - '.$issue; // The Subject of the email

//here you can define whatever you want to...
$headers  = "MIME-Version: 1.0\r\n";
//$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers .= "To: <".$email_to.">\r\n";
$headers .= "From: ".$email_from."\r\n";

//we control if sendmetoo is checked...
if($mailcc == 'sendtome'){
       $headers .= "Cc: ".$email_from."\r\n";
}
//$headers .= "Bcc: [email protected]\r\n";

$email_message = "Sales Level 2,";
$email_message .= "\n\nPolicy Number: " .$policynumber;
$email_message .= "\nClients Name: " .$name;
$email_message .= "\nPhone Number: " .$phonenumber;
$email_message .= "\nReason(s): " .$issue;
$email_message .= "\nPurchased Already: " .$purchased;
$email_message .= "\nAll info correct?: " .$infocheck;
$email_message .= "\n\nAdditional Information: " .$additionalinfo;
"\n\n\n\n". // Message that the email has in it

$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok && ((strpos($emailfrom, '@pethealthinc.com') === FALSE) || (strpos($emailfrom, '@24petwatch.com') === FALSE))) {
echo "<font face=verdana size=2><center>Your message has been sent<br>
to Sales Level 2<br>
Click <a href=\"#\" onclick=\"history.back();\">here</a> to go back</center>";

} else {
die("Sorry but the email could not be sent.<br> Please go back and try again!<p><u>Remember</u>, if you're not entering <b>YOUR</b> own email address, it is not going to work<br>ie:[email protected]");
}
?>

 

That didnt work though, it still sends to anything... then I tried under the advice of a friend...

 

<?php
//$name = $_POST["email"];
$name = $_POST["name"];
$policynumber = $_POST["policynumber"];
$phonenumber = $_POST["phonenumber"];
$issue = $_POST["issue"];
$purchased = $_POST ["purchased"];
$infocheck  = $_POST ["infocheck"];
$additionalinfo = stripslashes($_POST["additionalinfo"]);

//checkbox value readout
$mailcc = $_POST['sendmetoo'];

$email_to = "[email protected]"; // Who the email is to
$email_from = $_POST['emailfrom']; // Who the email is from
$email_subject = $policynumber.' - '.$issue; // The Subject of the email

//here you can define whatever you want to...
$headers  = "MIME-Version: 1.0\r\n";
//$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers .= "To: <".$email_to.">\r\n";
$headers .= "From: ".$email_from."\r\n";

//we control if sendmetoo is checked...
if($mailcc == 'sendtome'){
       $headers .= "Cc: ".$email_from."\r\n";
}
//$headers .= "Bcc: [email protected]\r\n";

$email_message = "Sales Level 2,";
$email_message .= "\n\nPolicy Number: " .$policynumber;
$email_message .= "\nClients Name: " .$name;
$email_message .= "\nPhone Number: " .$phonenumber;
$email_message .= "\nReason(s): " .$issue;
$email_message .= "\nPurchased Already: " .$purchased;
$email_message .= "\nAll info correct?: " .$infocheck;
$email_message .= "\n\nAdditional Information: " .$additionalinfo;
"\n\n\n\n". // Message that the email has in it

if ((strpos($emailfrom, '@pethealthinc.com') === FALSE) || (strpos($emailfrom, '@24petwatch.com') === FALSE))
{
$ok = FALSE;
}
else{
$ok = @mail($email_to, $email_subject, $email_message, $headers);
}

if($ok) {
echo "<font face=verdana size=2><center>Your message has been sent<br>
to Sales Level 2<br>
Click <a href=\"#\" onclick=\"history.back();\">here</a> to go back</center>";

} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>

 

The second I thought looked promising, but I am getting a syntax error on the line with the

 

if ((strpos($emailfrom, '@pethealthinc.com') === FALSE) || (strpos($emailfrom, '@24petwatch.com') === FALSE))

Can you clarify your question? It isn't really defined very clearly.

 

Sorry,  what I want is to have the form only send from 2 specific domain names, like...

[email protected], or

[email protected],

and I want it to only send from those 2 domain names...

 

 

Very simple example:

$from_domain = strtolower(strrchr($email_from, '@'));
if($from_domain!='@xyz.com'  && $from_domain!='@xxx.com')
{
    echo "That domain is not allowed.";
    exit();
}

 

That works perfectly!

 

Thanks so much! I was starting to get really frustrated. lol.

 

I looked up strtolower on php.net as well, and i understand why it works too. :)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.