I will be using G Suite (formally Google Apps) to host the email of a site that runs off a separate host.
However, there is a contact form on the website, I haven't looked at it yet, but I assume it will use the standard mail() function.
As I understand it mail() will still use the servers mail server to send the mail, it may be a dumb question, but I assume this won't cause any spam detection issues because of this? Like, I know some servers won't accept mail if the From and/or Sender headers don't match the server it is coming from (or in some cases if the email you set in these headers doesn't exist).
So, if the mail is hosted on G Suite, and the email address that is setup in the From/Sender headers exists on G Suite this won't cause any issues correct?
Lastly, I know it's probably a better idea to use SMTP to send the mail via Google, but I may not have that choice, so I wanted to find out the answer to the above just in-case.
Edit: As per Nima's answer, is this something that can be avoided, or only with using Googles SMTP server to send with?
If you want it simple, then simple use SMTP.
Because of spam, multiple mail server provider are blocking mails from mail servers that have no correct RDNS (Reverse DNS) and MTA name configured.
You want to make sure that all three names are matching according to your MX Record:
Sender Hostname (e.g *mail#demohost.com, note that from can be what ever you want)
MTA-Name/HELO-Hostname (Configured in Mailserver, e.g demohost.com)
RDNS (Basicly it gives per IP-Adress the Hostname (e.g 42.42.42.42 -> demohost.com)
Also make sure your php.ini has the correct configuration for your Mail Server. Congrats you can now send Mails using mail(...).
As I said, it's probably most simple by just using SMTP. Assign the hard work to a hoster.
When you use GSUITE for hosting emails, it's obvious that you will be providing some domain name to GSUITE.
Now emails are marked spam and not spam based on the content as well as certificates of sending server and sending servers have different services for Transactional and Marketing Oriented emails. And GSUITE only provide transactional mail service, and transactional mails from a mail service --having valid certificates and not black listed-- lands directly into Inbox or Other Label, but Spam/Promotion.
Now GSUITE is having all correct certificates and I don't think there is any consumer oriented mail service provider, which blocks emails coming from google servers.
Other Question:-
Does the From Address in E-MAIL headers matters?
Upto now I have never seen from address impacting anything on receiving servers, but some consumer mail services block the usage of from address other than the account email address, just like mobile operators don't let us use someone else's caller id(Ideally).
But mail service providers to businesses let you use any address as from value in e-mail headers.
Edit:-
If you are still unsure about delivery of emails, you can use replyTo header with out any problem.
PS:- I have tested this myself with thousands of emails but using SendGrid servers.
http://php.net/manual/en/function.mail.php
The Windows implementation of mail() differs in many ways from the
Unix implementation. First, it doesn't use a local binary for
composing messages but only operates on direct sockets which means a
MTA is needed listening on a network socket (which can either on the
localhost or a remote machine).
On linux the sendmail executable is used to talk to the SMTP server configured on windows you can / could configure mail() function to use SMTP
So the best way is to use SMTP directly to send the email to Gmail to send the email.
Taken from:
https://stackoverflow.com/a/33506709/623150
Here is a way to do it with PHP PEAR
// Pear Mail Library
require_once "Mail.php";
$from = '<your#mail.com>'; //change this to your email address
$to = '<someone#mail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your#gmail.com', //your gmail account
'password' => 'snip' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
If you use gmail smtp remember to enable SMTP in you gmail account,
under settings
On a Linux Server you can't use SMTP via the mail function.
Related
I want to enable my website users to send an email.
I use PHP and my host is GoDaddy. I assume that PHPMailer is the best option.
I think my problem is trying to connect to GoDaddy's PHPMailer.
Should I use another PHPMailer?
My code is based on an example on your site which is supposed to work.
It appears that the lines:
require_once "PHPMailerAutoload.php";
$mail = new PHPMailer; //PHPMailer Object
prevent the subsequent code from working.
Please help.
<?php
if(isset($_POST['send'])){
echo "Sending";
require_once "PHPMailerAutoload.php";
$mail = new PHPMailer; //PHPMailer Object
$mail->setFrom('sender#example.com', 'Rob');
// $mail->addAddress("my godaddy webmail"); //Recipient name is optional
echo "still Sending";
$mail->addAddress("recipient#example.com"); //Recipient name is optional
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Email Test";
$mail->Body = "<i>This is a text</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent successfully";
}
}`enter code here`
?>
<form method="post">
<input type="submit" name="send" value="Send">
</form>
Pretty much all virtual hosting servers are banned from sending mail by being placed on an email blacklist. As you might imagine, this is to prevent spammers from simply firing up a new virtual server and sending gobs of spam mail. It's a necessary protection for the internet at large.
It's important to realize that the PHP mail() function just returns TRUE if your local server accepted the mail message for outgoing delivery. This just means that the local software running on your server told PHP it would try to send the email. This in NO WAY guarantees that the mail will look legitimate to all the mail servers that might end up handling this mail message. If you send mail this way, your mail is generally unlikely to be delivered.
That being the case, you'll need your PHP code to send its outgoing email through some server that is NOT on an email black list. There are a variety of mail-sending services like SendGrid, MailChimp, Amazon SES, etc. that offer SMTP access. I.e., you connect to their servers using the SMTP protocol and send your mail that way. The PHPMailer readme is probably a good place to start and has an example script that connects to an SMTP server to send outgoing mail. The trick is to get the right username, password, port, and SMTP settings -- and this tends to vary depending on who you use to deliver your mail.
If your mail volume is small enough, you can probably get away with just using a regular old gmail account.
It is important to realize, too, that just sending off an email using PHPMailer is not itself sufficient to make sure the mail gets delivered. Modern spam filters running on mail systems make use of a raft of modern, interlocking schemes to check if a mail message is legitimate or not.
In addition to the PHPMailer steps, you might also need to set up an SPF record on your domain, and possibly DKIM and DMARC credentials as well -- these are modern schemes to telegraph to other machines that your server is a legitimate source of email.
SPF is pretty simple and involves creating DNS records for your domain that identify your server as a valid source of mail.
DKIM and DMARC are a bit more involved but can dramatically improve your mail delivery rate.
I want to send mail to inbox using smtp mail method using PHP.Now mail go to spam instead of inbox,i am using smtp mail method.I had set the hostname,username and password.
<?php
define("SMTP_HOST", "mail.test.us"); //Hostname of the mail server
define("SMTP_PORT", "25"); //Port of the SMTP like to be 25, 80, 465 or 587
define("SMTP_UNAME", "tttt");
//Username for SMTP authentication any valid email created in your domain
define("SMTP_PWORD", "tttt"); //Password for SMTP authentication
?>
Mail code
//smtp mail
$mail = new PHPMailer;
$mail->Host = SMTP_HOST;
$mail->Port = SMTP_PORT;
$mail->SMTPAuth = true;
$mail->Username = SMTP_UNAME;
$mail->Password = SMTP_PWORD;
$mail->AddReplyTo("test#test.com", "zamisoft");
$mail->SetFrom("test#test.com", "zamisoft.com");
$mail->Subject = $subject;
$mail->AddAddress($to, '');
$mail->MsgHTML($message);
$send = $mail->Send();
$mail->ClearAddresses();
//smtp mail
Anybody give any solution for these issue?
Add Headers to your email
$headers='From: ann#zamisoft.com \r\n';
$headers.='Reply-To: ann#zamisoft.com\r\n';
$headers.='X-Mailer: PHP/' . phpversion().'\r\n';
$headers.= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1 \r\n';
$headers.= "BCC: to";
It's been a while since I've played with PHP mail, but if that doesn't work it should put you on the right track.
Make sure you have SPF and DKIM setup. Since you are mailing from your own server, this is highly recommended.
Here is a link to Namecheap with screenshots. I couldn't explain it better:
https://www.namecheap.com/support/knowledgebase/article.aspx/9214/31/email-authentication-tool-in-cpanel-spf-records
Also, there are various checkers out there that well validate your SPF, DKIM, and check other things, and give it a score.
http://www.port25.com/support/authentication-center/email-verification/
https://www.mail-tester.com
http://dkimvalidator.com
The only things you can do when mailing from your own server. Use SPF and DKIM. Stay away from spammy words. One wrong word can make the difference of spam or inbox. Have a baseline email and baseline subject for testing. I had a slogan of mine that landed me in the spam folder, so I had to change it because I wanted it in the signature of my emails. Using certain link shorteners could land you in the spam folder. I am not saying they do, but using bit.ly or tinyurl links could land you there. Using tinypic or another image hosting service could. Your domain name could be the problem! The from name..
Remember, every word (whether it's in your email address, domain name, hostname, subject, or the body of the email) is looked at.
As well as your server's IP address. Is it on any blacklists? Check it with http://mxtoolbox.com/blacklists.aspx
Without one of us actually getting on your server and sending dozens of test email to see what is actually causing it, I can only tell you the dozens of things to check.
With all that said, mailing off your server sucks and I don't recommend it. I suggest using SendGrid or Mailgun. I had a client landing in the spam folder, on a new server, clean IP, new domain, everything. I put him on SendGrid and he wasn instantly going into the inbox.
For development, or a low level site, mailing off your server is fine if your hitting the inbox most of the time. But anyone that takes their site serious and the emails hitting the inbox is important, use a 3rd party. Most servers (from GoDaddy, Hostgator, etc.) are not for sending emails to tens of thousands of customers. They are web servers, not mailing (MX) servers, and they will tell you that it isn't their problem.
Update: I forgot to mention reverse DNS. You should have rDNS setup, and that is done by your upstream. So you would need to contact your webhost and ask them to setup "Reverse DNS" on your server.
Can you show the content of your mail? Are you trying to send HTML or text mail? Maybe the provider is on blacklist, check the sending IP address (see mail header) at a blacklist check.
I had these spam problems with Google Mail only when sending with mail() - after the change to SMTP all works properly.
I stumbled on the following script today for sending an e-mail using PHPMail.
<?php
$to = "some_address#domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my_address#domain.com";
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
echo "Mail Sent.";
?>
Above can be runnable through php mail.php and instantly you'll get an e-mail sent to $to from $from despite not needing to set outgoing/ingoing servers out.
It really intrigued me, since my CMS uses an SMTP outgoing server (well, same way Mail PHP does), which I need to set up with my Outlook SMTP username and password - some sort of verification.
However, about Mail PHP just.. sends an e-mail. To the address you set it as. From the address you set it as.
Looking at PHP docs it does not really reveal how it works. Does Mail PHP not have any issues with spamming since anyone can send anyone anything anytime programmatically without verification of the from identity?
EDIT:
It's rather funny the people in the comments were talking about the POTUS, since I had the exact thing in mind:
It did land in my junk folder, but I'm sure it isn't hard to make this look convincing enough and still be considered "oh damn spam filter lost my e-mail!"
The mail function uses the settings from php.ini. The details of this configuration can be found in Mail Runtime Configuration.
The defaults can be set in php.ini, although you can override them using ini_set.
I bet you sent the mail from a PHP script on a hosted server. That server probably has SMTP settings configured beforehand. If you would try this locally on a WAMP/LAMP server, you would have to do this configuration yourself, since PHP cannot read your Outlook/WhateverMailclient settings.
As stated in the comments, you can specify the sender/from address yourself. SMTP doesn't require this to be the actual sender domain, so that's why this works. The missing link is the pre-configured SMTP server of your host.
Some relay servers do check for this, and your mail might be blocked or sent to a junk mail folder. You can however configure this in your DNS to indicate that <Your server's IP> is indeed allowed to send email for <yourdomain>. For more information about that subject, you might want to read this question on ServerFault.
It uses the smtp protocol or send_mail, you can even configure what php should use to send mails in php.ini. It can send e-mail but the e-mail will end-up in your spam filter take a look to DKIM and SPF records for more information
I asked a similar question earlier, but the context has changed a bit. I want to use swiftmailer to send an email in Symfony 2. The problem is I'm using the gmail SMTP server, and so when my message arrives, my email client shows it from gmail.com, rather than mydomain.com. How can I fix this?
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom(array('digest#mydomain.com' => "Digest"))
->setSender(array('digest#mydomain.com' => "Digest"))
->setCharset('iso-8859-1')
->setContentType('text/html')
->setTo('myemail#gmail.com')
->setBody($this->renderView('email.html.twig', array()));
$this->get('mailer')->send($message);
The Gmail SMTP server only allows you to send mail using the email address you're aithenticating with. So if you configured Symfony with
mailer_transport: gmail
mailer_user: myemail#gmail.com
mailer_password: ******
All your messages we'll look like they're from myemail#gmail.com
What you can do maybe is use another smtp server that is more flexible in the types of From addresses they will allow. If you are on a local development server, you could use your ISP's SMTP server, or use one of the various email as a service provider, such as Sendgrid, Mailjet or postmarkapp
They all allow you to send messages from any address you can prove ownership of, after some configuration steps.
One thing that may be worth trying also if you really want to use the gmail smtp server, is to define your from address in your "Send mail as" Gmail configuration (in Settings -> Accounts). This will let your app send email using the configured adresses in the From: field.
I have tested my email server on allaboutspam.com to see why the emails are beeing considered spam by hotmail and gmail servers.
The results was amongst other faults, the BATV.
This is the complete result from allaboutspam.com on my BATV:
BATV is a mechanism wherein an outgoing Email server adds a tag to the Envelope From address of all outgoing Emails. For example, if an Email address goes out with From address as <info#allaboutspam.com>, the Envelope From is changed to <prvs=SBDGAUJ=info#allaboutspam.com>, where 'SBDGAUJ' is the added tag. This tag is generated using an internal mechanism and is different for each email sent.
If any bounce is received by the Incoming email servers, they are checked to see if the Bounce address has the proper tag (in above case 'SBDGAUJ'). If not, the email is rejected.
Could somebody explain this in simpler words... How is it configured?
currently I have this setup when sending email with php:
$mail_message="text_text_text_text";
$headers="MIME-Version: 1.0"."\n";
$headers.="Content-type: text/plain; charset=UTF-8"."\n";
$headers.="From: Skuffen <no-reply#domain.se>"."\n";
$subject="SUBJECT HERE";
mail($email, '=?UTF-8?B?'.base64_encode($subject).'?=', $mail_message, $headers, '-fno-reply#domain.se');
This is a swedish language so you know (utf-8)...
Thanks
I think that you need to set this up in your Mail Transfer Agent. The PHP mail() command sends mail through the local sendmail (or compatible, like Exim, Postfix or Qmail) installation. That's where BATV needs to be configured.
If you are on a simple shared hosting, contact your hosting provider.