2

I am making the validation part of the account registration of my website, where a message is sent to the user email with a link to validate the account. I am using 000webhost hosting. I've read that their mail service is poor and that I should get Google Apps service. So I did, I changed the MX record to Google's.

But when I use the mail() function, it is still sent by 000webhosts service; I tested it sending a message to my account and the sender is:

Info info@mydomain.com through srv19.000webhost.com

Shouldn't the service be Google's one? I changed the MX record, but don't know.

And another question, what happens if I create a mail @mydomain.com with Google Apps, and another one with the same adress in my hosting CPanel?

I hope you help me

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Agusfn
  • 83
  • 2
  • 12

2 Answers2

1

The 'through' message is shown by Google when you don't use DKIM to sign your message.

If you use google apps to send the email, you can opt to use their emailing servers, which will be recognised by google, so the message will not be shown then.

Edit: let me add that getting sendmail to send (correctly!) dkim signed messages isn't as easy as it should be. Many email servers will add additional headers, or change headers you have specifically set. If you sign any of these headers, the signature will no longer match.

Generally it is easier to use SMTP to send to a proper email server directly. SendGrid, Amazon SES or Postmark are companies that will make your life a whole lot easier - at a very reasonable cost.

Edit2: Just read the question again, it's getting late: you've correctly set the MX records to Google Apps, but that's for receiving email, not for sending. So if you are sending email it will still be sent using your own server.

If you want to use Google's servers, there are a few options:

  1. use a emailing framework and connect to their SMTP server using PHP (might be lots of work).
  2. setup sendmail to forward all email to google's SMTP servers (is a pain setting up, if your host even supports it).

In most cases, (1) seems to be the only option.

creativedutchmen
  • 515
  • 2
  • 10
  • Tricky. What kind of application are you trying to send email from? Does it have the mail() functions littered throughout the code, or are they bundled in an emailing object? – creativedutchmen Aug 19 '12 at 19:13
  • I am using mail() with 000webhost free service currently, but i'd rather use my google apps service. And i don't know how. – Agusfn Aug 19 '12 at 22:30
  • Yes, I understand. What application are you trying to send the mail from? Wordpress? Joomla? CakePHP? LemonStand? Do you have the option to change from sendmail to smtp? – creativedutchmen Aug 19 '12 at 22:34
  • I am using my own php files i am writing. I don't know if i have the option but as far as i know this object (sendmail) works with smtp, isn't it? – Agusfn Aug 19 '12 at 23:58
  • Well, yes and no. Sendmail writes to the mail spooler on your server. Most sendmail clients are setup to send the email using an installed smtp server like exim4. The problem is we don't want to use that server, we want to use the servers by google. So that's why I said you have two options: change the sendmail configuration, or change your PHP code to talk to the smtp servers directly. If it is your own code, and it is still manageable, I would strongly recommend to use something like swiftmailer. http://swiftmailer.org/. – creativedutchmen Aug 20 '12 at 08:11
  • There are very useful answers in [this post](http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page). Just take a look and see if you can implement it. – creativedutchmen Aug 20 '12 at 08:33
  • Thank you for your answer, i searched how to use swiftmailer and i've found this: stackoverflow.com/questions/3536836/trying-to-send-mail-using-swift-mailer-gmail-smtp-php In localhost works fine, but in my host give the following error; http://pastebin.com/J2DWmQui I put it in pastebin because it's a large text. – Agusfn Aug 20 '12 at 17:41
  • Can you share how you've set it up? Google is quite picky when it comes to settings, so it could be something very simple. – creativedutchmen Aug 20 '12 at 19:47
  • Something you could try is setting the port to 587, and changing 'ssl' to 'tls'. For some reason some ISPs block the standard ssl port (mine, for example), so it is worth a shot. – creativedutchmen Aug 21 '12 at 09:04
  • Well, still getting errors, i think i should buy at least a cheap host but currently keep using the mail service of 000wh Thank you for your answers – Agusfn Aug 21 '12 at 22:18
  • No problem. If you continue to have problems sending email, I would really look at amazon SES, SendGrid and PostMark. They provide (smtp) email servers that just work. I've recommended them elsewhere on SO too; they solved a lot of my problems for just a few euros per month. And, no, I am not affiliated with any of them. – creativedutchmen Aug 22 '12 at 20:07
0

When you use mail(), by default PHP sends the message using the outgoing mail server that your webserver's configured to use -- this is almost always going to be a mail server running on that same host.

So, what you need to do is use a different function to send your mail, which will connect to google's servers rather than your own webserver.

animuson
  • 53,861
  • 28
  • 137
  • 147
Jeremy Warne
  • 3,437
  • 2
  • 30
  • 28