how to verify an email address?

2 posts Page 1 of 1
Contributors
shikara
Just Registered
Just Registered
Posts: 1
Joined: Thu May 23, 2024 9:02 pm

how to verify an email address?
shikara
Hi everyone,

I’m looking to find out how to verify an email address...

I have a recommendation script on my site that works well if you enter an address like blou@blabla.com, but if I just enter blou, I get an error message that doesn’t display “nicely,” I would say :lol:

Here’s what it says:
Code: Select all
Warning: mail() [function.mail]: Invalid mail. to = [blou] in /mnt/128/sdb/2/c/blingbling/pages/rec.php on line 11
So if someone could point me to a simple tutorial to fix this problem, I would really appreciate it!

For your information, here is my script:
Code: Select all
<?php
if($_POST)
{
    if(empty($_POST['nom']) OR empty($_POST['email']) OR empty($_POST['content']))
    {
        echo "<p>Please fill in all the fields.</p>";
    }
    else
    {
        mail($_POST['email'], stripslashes($_POST['nom'])." recommends a site to you", stripslashes($_POST['content']), "From: ".$_POST['email']."\nReply-To: ".$_POST['email']);
        echo "<p>Your friend has been notified.</p>";
    }    
}
?><form action='<?php echo $PHP_SELF; ?>?page=rec' method='post'>
<fieldset>...etc</fieldset></form>
So from what I have seen so far, it’s this:
Code: Select all
!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4
"solve the problem first then write the code"
Clean your electronic address list
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Been to long since I've been on here. I made an example below with an email filter.

Documentation can be found here: https://www.php.net/manual/en/function.filter-var.php
Code: Select all
<?php
	if ($_POST) {
		if (empty($_POST['nom']) || empty($_POST['email']) || empty($_POST['content'])) {
			echo "<p>Please fill in all the fields.</p>";
		} else {
			if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
				echo "<p>Please enter a valid email address.</p>";
			} else {
 				mail($_POST['email'], stripslashes($_POST['nom'])." recommends a site to you", stripslashes($_POST['content']), "From: ".$_POST['email']."\nReply-To: ".$_POST['email']);
            			echo "<p>Your friend has been notified.</p>";
			}
		}
	}
?>

<form action='<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>?page=rec' method='post'>

</form>
Image
2 posts Page 1 of 1
Return to “Help & Support”