PHP email Validation of IBM email only, (World wide) - php

I am pretty new to PHP, How do I validate an email address to have an IBM domain only? Valid address are:
XXXXX#us.ibm.com
XXXXX#in.ibm.com
XXXXX#ro.ibm.com
XXXXX#ibm.com
The PHP should be able to accept any of the above.
Please help
Thanks

Split on # then verify with a regex.
list($username,$domain) = explode('#',$email);
if (preg_match('/ibm\.com$/',$domain))
{
echo "yup it's ibm.";
}

First thing to check, is if the email address you got from the email headers is valid i.e.:
John Adams <john#us.ibm.com>
"John Adams" <john#us.ibm.com>
john#us.ibm.com
Then you can verify if it came from an IBM domain by:
if(preg_match('/#([a-z]{2}\.)?ibm.com/i', $emailaddress)) {
# email is from an ibm domain
}
Finally and this is a hard part, make sure that the email was sent from a server owned by IBM, because even me can send you an email with "arvin#ibm.com" as the email address indicated in the From field.
You can list all the IP addresses of IBM's email servers then check if the email originated from them using the email's header fields. Or if your server does SPF checking you can check if the Received-SPF field of the email is "pass".

Related

What e-mail address from header will be used when answering by holiday message?

I have corresponding problem. I'm sending newsletters by PHP scripts. E-mail's headers are :
Return-Path: <no-reply#vojta.cz>
From : No Reply <no-reply#vojta.cz>
Reply-To : Vojtech Tuma <me#vojta.cz>
What heppen if this e-mail is sent to mailbox where is set auto-answer (I'm on vacation blah blah...) Which address from header will be used for auto-anser as "To" header parametr ?
Thanks.
It depends on how the receiver's email client is configured. If their client is configured to ignore Reply-To, it will get sent to no-reply#vojta.cz, otherwise it will send to me#vojta.cz.
You literally have no control over this.
When you get an Auto Answer You'll get the following headers:
X-Autoreply: yes
Auto-Submitted: auto-replied
Standard wise It'll go back to the Reply-To e-mail.
Please check RFC-3834 - Recommendations for Automatic Responses to Electronic Mail Item 3.1.2 .

PHPMailer and multiples destination addresses issue

Im using phpmailer to send emails and i check that when i add some addresses and just one of them is an invalid address (not exists) E.G. "asdfasfasf#asdfasdfsfsfs.commm" and send the email i see that the email was sent (to correct addresses) and i have no idea how to check if one of the adresses is wrong to be able to log that issue before sending the email.
The code to send and add addresses is this:
foreach($options['emails'] as $email){
$mmail->AddAddress($email[0], $email[1]);
}
if (!$mmail->Send()) {
echo "error";
}else {
echo "sent";
}
Thanks in advance
Take a look at filter_var to validate the syntax:
if (filter_var($email[0], FILTER_VALIDATE_EMAIL)) {
// email address is considered valid
Note that there are ways to connect to the recipients SMTP server and ask if the email actually exists (see https://code.google.com/p/php-smtp-email-validation/ for example) however many email servers won't honor these queries anymore, due to spammer abuse.

PHP e-mail to spam

I'm trying to email new registered users for email verification (PHP) but i don't get it, why would an email be sent to SPAM, i already checked out similar questions and all answers are about Headers,
It seems a bit complicated for me to get known to those headers and how are they being verified,
By sender website ? lets say i sent as user#google.com and the actual server domain is domain.com, how would it know? and is it one of the main reasons why it goes to spam ?
I am using VPS, does it has anything to do with it ?
I'm just trying to understand the clear/simple reasons of why would an email be checked as spam
and what if i sent from the server IP and not the domain itself
Most of the mail servers will do Reverse DNS lookup to prevent people from domain.com pretending to be from otherdomain.com. It will check if the IP address from which the email was sent resolves to the same domain name of the email sender. Yahoo and other big companies will also use DKIM to verify you.
Often your message can end up in Bulk/Spam if it doesn't have much content, or if you sent a lot of the same content to one server.
Here's a good article about what web developers should know about sending email that might help you understand the subject.
1) Check headers. You could use any email sending library such as PHPMailer (http://code.google.com/a/apache-extras.org/p/phpmailer/wiki/PHPMailer#Documentation_and_Resources)
2) Check hosting server. If your is using shared hosting then most probably it has been blacklisted by the email domain.
Configure an email address on your domain, replace me#mydomain.com with your newly created email address on your domain andid#hotmailOrgmail.com with your Hotmail/Gmail id in the following script.
Also replace Your Name with your name in the following script and test it on your server:
<?php
$myName = "Your Name";
$myEmailAddressonDomain = "me#mydomain.com";
$myPreferredEmailAddresson = "id#hotmailOrgmail.com";
$mail = $_POST['email_field'];
$clientName = $_POST['name_field'];
$subject = $_POST['subject_field'];
$text = $_POST['message_field'];
$headers = 'From: "$name" <$yourEmailAddressonDomain>'.PHP_EOL.'Reply-To: '.$_POST['mail'].PHP_EOL;
$to = '"$yourname" <$myPreferredEmailAddresson>';
$message = $text.PHP_EOL.PHP_EOL."---".PHP_EOL."From: ".$name." <".$mail.">";
/* Server-side form validations */
$err = "Error with ";
if (!checkLen($name)) {
$err.='Name';
} else if (!checkLen($mail) && !checkEmail($mail)) {
$err.='Email';
} else if (!checkLen($subject)) {
$err.='Subject';
} else if (!checkLen($text)) {
$err.='Message';
}
if (strlen($err)>11) {
echo $err.' field';
exit;
}
/* end validations */
elseif (mail($to, $subject,$message, $headers)) {
echo "<span style='color: #336600'>Your message has been sent.</span>";
} else {
echo "An error occurred, please try again.";
}
function checkLen($str,$len=1)
{
return isset($str) && mb_strlen(strip_tags($str),"utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[#][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
?>
The email will land on your Hotmail/Gmail inbox (or any non-spam) folder via your domain's email address.
Note: Clicking Reply in the received email would show you the client's email address (as we have set in Reply-To header above)
Make appropriate changes and you are good to go.
as you are operating VPS, you may consider setting up DKIM and SPF on your server, they are used by mail services like Gmail to classify your server as a legitimate server.

Checking for valid email addresses

I'm running a website with more than 60 000 registered users. Every week notifications are send to these users via email, now I've noticed some of the mail addresses do not exists anymore eg. the domain address is valid but the email name en asdas# is not valid anymore since person does not work at a company anymore etc. Now I'm looping through the database and doing some regular expression checks and checking if the MX records exist with the following two functions
function verify_email($email){
if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*#[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){
return false;
} else {
return true;
}
}
// Our function to verify the MX records
function verify_email_dns($email){
list($name, $domain) = split('#',$email);
if(!checkdnsrr($domain,'MX')){
return false;
} else {
return true;
}
}
If the email address is in an invalid format or the domain does not exists I delete the users account. Are there any methods I could use to check if the email address still exists or not if the domain name is valid and the email address is in the correct format? For example abc#test.com does not exist anymore but test.com is a valid domain name.
NOTE: If a mail is send to users and the email address does not exist anymore i get a email in my inbox resulting in 1000 per day which I'm trying to avoid.
The standard way is to connect to the remote mailserver and send it a VRFY command. However, some servers don't allow that because it makes it much easier for spammers to find out valid e-mail addresses. You can also try sending it a RCPT TO command (you'll get a 550 response if the address is invalid), but they tend to block you if you do that too many times, for the same reason
If you're already getting bounced e-mails in your inbox, it seems like you could just parse those and automatically remove people from your list that are causing delivery failures

email application help. Send email to made up email address which is redirected to real email

I'm wondering how i would go about making the following application:
a user signs up, say with the username "johny-jones".
Lets say for example that my domain is www.example.com
if anyone emails johny-jones#example.com this email is redirected to johny-jones REAL email address
The simplest option is to tell your smtp server to forward all ingoing mails to an external program (your php script). For example, for qmail this will be like | php myphpscript.php in .qmail file. Your script will read email from stdin and resend it to the real address.
You're basically describing a mail transfer agent AKA mail server. So all you need to do is a server to run it on, the required MX DNS records, and an API that allows you to configure forward addresses. Look through the documentation of the servers
listed here to see which ones offer the latter.
Just pipe all orphan email (specific to that domain) to ur PHP script and use something like this to extract the email content:
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
then extract the "to" field and if it belongs to a user .. forward the email to him.If you have cPanel .. this is even easier. goto mail > default address > set default address and instead of putting an email address there put something like this
"|php -q /home/whatever/public_html/pipe.php" .. ofcourse without the quotes

Categories