Externally Hosted Email and Using PHP to Send Email

I will use the G Suite (formally Google Apps) to host an email site that runs from a separate host.

However, there is a contact form on the website, I have not looked at it yet, but I assume that it will use the standard mail() function.

As I understand it, mail() will still use the mail server server to send mail, this might be a dumb question, but I assume that it will not cause problems with spam detection because of this? For example, I know that some servers will not accept mail if the From and / or Sender headers do not match the server from which it comes (or in some cases, if the email address you specified in these headers does not exist).

So, if the mail is hosted in the G Suite, and the email address that is configured in the From / Sender headers exists in the G Suite, will this not lead to errors?

Finally, I know that it is probably best to use SMTP to send mail through Google, but I may not have that choice, so I would like to find the answer to the above just in case.

Edit: According to Nima's answer , is this something that can be avoided or just using the Googles SMTP server to send?

+5
source share
3 answers

If you want this to be simple, just use SMTP .

Due to spam, several mail server providers block mail from mail servers that do not have the correct RDNS (reverse DNS) and MTA name.

You want all three names to match your MX record:

  • Sender hostname (e.g. * mail@demohost.com , note that maybe what you want from )
  • MTA-Name / HELO-Hostname (configured in Mailserver, e.g. demohost.com)
  • RDNS (basically it gives the host name to the IP address (for example, 42.42.42.42 -> demohost.com)

Also make sure your php.ini has the correct configuration for your mail server. Congratulations, you can now send Mails using mail(...) .

As I said, it is probably the easiest, just using SMTP. Assign hard work to the hoster.

+2
source

When you use GSUITE to host emails, it is obvious that you will provide some GSUITE domain name.

Now emails are marked as spam, not content-based spam, as well as server sending certificates, and sending servers have different services for transactional and marketing-oriented emails. And GSUITE provides only a transactional mail service, and transactional letters from the mail service - with valid certificates, not black ones - go directly to the Inbox or Other Tags, but Spam / Promotion.

Now GSUITE has all the correct certificates, and I don’t think there is any consumer mail service provider that blocks emails from google servers.

Another question: - Does From Address in the E-MAIL headers matter? Until now, I have never seen an address affect anything on the receiving servers, but some consumer email services block the use of an address other than the email address of the account, just like mobile operators do not allow us to use another caller ID subscriber (ideally). But enterprise email providers can use any address as the from value in email headers.

Edit: - If you are still not sure about the delivery of letters, you can use the replyTo header without any problems.

PS: - I myself tested this with thousands of letters, but using SendGrid servers.

0
source

http://php.net/manual/en/function.mail.php

The implementation of Windows mail () is very different from the implementation of Unix. Firstly, it does not use local binary code for composing messages, but it works only on direct sockets, which means MTA needs to be listened to on a network socket (which can either be on localhost or a remote machine).

In linux, the sendmail executable is used to communicate with the SMTP server configured on Windows, you can / can configure the mail() function to use SMTP

Thus, the best way is to use SMTP directly to send email to Gmail to send email.

Taken from: fooobar.com/questions/64844 / ...

Here's how 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, do not forget to include SMTP in your gmail account in the settings

On a Linux server, you cannot use SMTP through the mail function.

0
source

Source: https://habr.com/ru/post/1270569/


All Articles