Forum Moderators: coopster
Still near the bottom of the learning curve here so please bare with me! I have two problems with the code below.
Firstly, when trying to validate the e-mail address using what appears to be a more or less "standard" validation string, I find that a .co.uk address validates as expected. However, a .co.ukk address is also accepted as valid. I have tried putting different values at the end of the string [in place of the +$ bit] without success. Is this just one of those things I have to accept, or is there a way I can reject a .co.ukk [same problem with a .ac [.acc] etc].
Secondly in the "mail($to,$subject,$message,$from);" function. If I echo the variables after the message has been sent it appears that $to, $subject, $message and $from are all present and correct. However, whilst the other variables are being sent in the e-mail, the $from variable is not, and the e-mail appears to be coming from host@theirserver.com. I've been going "bog eyed" trying to find stupid mistakes but to no avail. What am I missing?
<?php
$to = "admin@mydomain.co.uk";
$subject = "E_mail message from website";
$from = "me@mydomain.com";
$address = "visitor@visitorsdomain.co.uk";
$message = "Test Message";
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
{
mail($to,$subject,$message,$from);
$msg = "Message Sent";
}
else
{
?>
<form action="javascript:history.back()" method="" name="">
<input name="Return" type="submit" value="Return">
</form>
<?php
$msg = "You have not entered a valid e-mail address <br> Please re-enter";
}
echo "msg: ",$msg, "<br>";
echo "To: ",$to, "<br>";
echo "Subject: ",$subject, "<br>";
echo "From: ",$from, "<br>";
echo "Address: ",$address, "<br>";
echo "Message: ",$message, "<br>";
?>
Many thanks in advnce for your help.
- match 0 or more
- match 1 or more
- match a specficied number of times, defaulting of course to 1
If you knew that all addresses would have TLDs of two chars or three chars, you would be all set, but you don't. The only way I can think of would be to have a list of all TLDs and then compare against it. At that point, though, it might be easier to just do your rough validation and then send a confirmation e-mail, requiring the user to click on a link in that mail before being fully registered. Then you know that not only does the address exists, but it belongs to someone who wants to sign up for your service.
$from = "me@mydomain.com";
I believe that what you need here is along the lines of
$from = "From: me@mydomain.com"
or even
$from = "From: me@mydomain.com\r\nReply-To: me@my_other_domain.com"
I take your point about regex - I suppose I had assumed that, as most people seem to use this "formula" when validating e-mails, it would be foolproof. Sometimes when your head is down and you are running, it's important to remember to look up from time to time and check you are still running in the right direction! Thanks for putting me back on course!
Also, the $from = "From: me@mydomain.com" solved the second problem too.
Thanks again for your help.
Spook
I have:
$email = "me@mydomain.co.uk";
$maildomain = substr(strstr($email, '@'), 1);
if (!( @getmxrr($maildomain, $temp) ¦¦ @gethostbyname($maildomain)!= $maildomain ))
echo "The domain does not exist.";
which I cut and pasted from above, and I replaced the broken pipe [thanks for the "heads up"].
However, I am getting a parse error on the line if(!( @get etc..
I have spent some time reading up on both getmxrr and gethostbyname but can't spot the problem.
Can anyone shed some light on this please?
Many thanks
Spook
I originally got this from the O'Reilly Web Database Book (see original code [webdatabasebook.com]).
Now that I look around there's plenty of other examples of this technique.
[developer.com...]
[zend.com...]
$to = $_POST[to];
$from = $_POST[from];
$subject = "Your order has been sent -- confirmation to follow";
$message = "$name,\n\nYour order has been sent -- confirmation to follow upon receipt.";
$headers = "From: $from\n";
$headers .= "Reply-To: $from\n";
// Send the message
$ok = mail($to, $subject, $message, $headers);
if (!$ok) {
echo "<p>Your confirmation e-mail could not be sent. Sorry!</p>";
}
Ask if you have any problems with this.
Regards,
DK
I was going to write to say that your code had a minor problem with LF versus CRLF, but then the issue got complicated enough that I started another thread [webmasterworld.com]
Always learning...