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.
Related
My email form is working but will not send an email when the user uses a aol.com and yahoo.com email address. What do I need to change?
PHP file is hosted by godaddy.
I'm a designer, and PHP is not my forte, can you explain an answer with changes to my existing code (if the change is with the code at all.) This problem is very frustrating.
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
// http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "mysite#mysite.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
//Set a 200 (okay) response code.
// http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
// http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
// http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
The only thing that I can think of is that goDaddy has blocked these domains for sending emails, since mail() uses the servers settings
I also don't see any error in your simple code. Some things to consider:
Your new lines in the body and header should use CRLF \r\n, rather simply \n
You may also use additional parameters and setting your email as 5th parameter with the -f command (trusted user for the sending program).
Example:
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers,"-f".$email)) {
Since you're a designer, i also suggest to use tools like PHPMailer, that eases the e-mailing process and fixes some stuff for you.
Well that's because you're not supposed to be sending mail on behalf of email addresses you don't control through mail servers that are not authorized to do so. This is a rule about email that most people seem to ignore, but both Yahoo and AOL have both recently changed their policies to block the exact thing you are trying to do.
http://blog.mailchimp.com/aol-changes-dmarc-policy/
I would expect that this will become a thing that more and more mail providers do as time goes on.
What you should be doing is using an email address that you own to send out the mail, either through that domains outbound server or one authorized by the domain, and not trying to spoof someone else's address. In addition to not appearing to be shady as all get-out, you'll be far less likely to run afoul of DMARC and SPF policies, spam filters, and angry email admins perusing StackOverflow.
I tore out my hair over this issue for weeks. Finally figured it out today. If your form has an email field and it's named "email", and the user types an #aol or #yahoo email address, Formmail will act like nothing's wrong, but the form will not be sent.
It's an easy fix. Just use something else (anything else but "email") for the email field name, like "FromEmail".. Easy peasy.
If the user types something like dingbat#aol.com or doofus#yahoo.com:
This won't work:
<input type="text" name="email" size="30" maxlength="100" />
but this will:
<input type="text" name="FromEmail" size="30" maxlength="100" />
Good luck!
Chaz
i am new to php and web development. i am trying to confirm user,s email on signup by sending confirmation message on their email. But it is not working is the problem with my using localhost as a server or there is some other problem? here is my code
{
$to = $_POST['email'];
$com_code = md5(uniqid(rand()));
$subject = "Confirmation from OnlineShopping to $_POST['username']";
$header = "OnlineShopping: Confirmation from OnlineShopping";
$message = "Please click the link below to verify and activate your account. rn";
$message .= "http://www.yourname.com/confirm.php?passkey=$com_code";
$sentmail = mail($to,$subject,$message,$header);
if($sentmail)
{
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else
{
echo "Cannot send Confirmation link to your e-mail address";
}
}
my if($sentmail) condition is coming true and i am getting message that your confirmation link has been sent to your email address but i am not receiving any email in my inbox
Nowadays, ISPs usually block any smtp activity, you need a proper mail server. Easiest is to use the gmail smtp server to send mail, just to get you going.
There are plenty of ways to do that, just search "gmail smtp php" and you'll get a bunch of articles.
You need a host to send email with php. I recomend you to use .tk For a free domain and hostinger for free hosting. So you can use this function and test your stuff.
But you can also try changing the php.ini file. http://www.php.net/manual/en/mail.configuration.php
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.
I'm a newbie in PHP. My goal is to send an email to the user registered in my system.
Here is my code:
$msg= " Hi $gen./$lName, copy and paste this code in order to activate
your account copy and paste this code:$num" ;
$email = "$emailadd";
$name= "GoodFaith Network Marketing Inc.";
$subject = "Account Activation";
$message = wordwrap($msg,70) ;
$sender = "cjoveric#myalphaedge.com";
$mail_header="From: ".$name."<". $sender. ">\r\n";
$sendmail=mail($email, $subject,$message, $mail_header );
I was able to send an email, but my problem is I want to know if the user's email address exists in Yahoo, GMail or other mail services.
Is there any way I could filter out invalid emails?
Use SMTP mail the best and easy to use SMTP.
$mail->IsHTML(true);
$mail->From="admin#example.com";
$mail->FromName="Example.com";
$mail->Sender=$from; // indicates ReturnPath header
$mail->AddReplyTo($from, $from_name); // indicates ReplyTo headers
$mail->AddCC('cc#phpgang.com.com', 'CC: to phpgang.com');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send())
{
$error = 'Mail error: '.$mail->ErrorInfo;
return true;
}
else
{
$error = 'Message sent!';
return false;
}
Not really. About the best you can do is send an email and see if the user responds to it.
Doing a regex check on email address can be frustrating for some users, depending on regex. So, I recommend to skip your regex test and just send the verification email with a confirmation link -- anything else will leave your application brittle and subject to breakage as soon as someone comes up with a new DNS or SMTP extension. It's best to get that dealt with when their paying attention.
For example:
-a confirmation code that needs to be filled in your website
-a link, going to your website, that needs to be visited
And still it is uncertain whether the email is existing afterwards, as it is easy to simply create a temporary email to pass the validation and delete it afterwards.
Instead of validating email addresses you can use the Google API to let your users sign in using their account. It is also possible to use OpenID on a similar way. Though, even this is not 100% perfect. But heay, nothing is 100%. We all try to make is work as we want as much as possible. That's it.
PS: ICANN is expected to approve UNICODE domain names Real Soon Now. That will play merry hell with Regex patterns for email addresses.
I have a php mail script which works perfectly on a one host. However, when I attempt to use the same script on a network solutions host, the function returns true but no email ever sends.
//get mail function data
$case = $_POST['case'];
$to = addslashes(strip_tags($_POST['to']));
$message = addslashes(strip_tags($_POST['message']));
$subject = addslashes(strip_tags($_POST['subject']));
$message = addslashes(strip_tags($_POST['message']));
$from = "confirmation#website.co";
$headers = "From: $from\r\n";
//send email
if (mail($to,$subject,$message,$headers)){
//formatting for error message
$emailSent = "block";
$emailFailed = "none";
}
else //if the email fails to send
{
$emailSent = "none";
$emailFailed = "block";
}
?>
Does anyone know if different hosts require specific info in mail script?
This is a question for Network Solutions customer support. Sending mail from shared hosting servers is usually well locked down -- if they allow it at all, it's throttled. Also, calling mail just means the message was successfully passed to sendmail, not that the mail ever left the server. It could be sitting in a queue to be sent, it could have bounced for a million reasons beyond your control, etc.
Some hosts have this issue. On mine (Mosso), I had to adjust the last parameter (from) like so:
mail($to, $subject, $message, $headers, "-f".$from)
May not be the solution for NetSol but worth a try. I know some hosts disable the script and require using the smtp class to send mail.
This is assuming, of course, everything is correct with your DNS and MX records. If you're trying to send from an account that is different than the domain being sent from, some providers will automatically block that.
It maybe that they have not enabled php mail, but ask the host for specifics.
Looking at your code it is not cleaning the input sufficiently. take a look at the is_forbidden function here:
http://thedemosite.co.uk/phpformmailer/source_code_php_form_mailer_more_secure_than_cgi_form_mailers.php