Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i've read some threads here in SO that someone managed to use gmail's smtp server to send out messages from php script.

so if php sends a mail to peter@hotmail.com it looks like this:

Alternative 1:

  1. php tells sendmail (smtp server) to send the message
  2. sendmail sends the message to gmail's smtp server
  3. gmail's smtp server sends the message to hotmail's smtp server

so now i wonder, why should one use gmail's smtp server to send a mail? isn't it better just to send the message from sendmail to hotmail's smtp server?

Alternative 2:

  1. php tells sends to local sendmail
  2. sendmail sends to hotmail's smtp server

Alternative 3:

  1. php sends the message to gmail's smtp server
  2. gmail's smtp server sends to hotmail's smtp server.

Alternative 4:

  1. php sends the message to hotmail's smtp server. (why does this not work? why have a intermediate smtp server (that actually acts like a pure client) to send to another smtp server?

correct me if im wrong, but isnt all that requires for a mail to be sent a communication between TWO smtp servers, the senders and the receivers (in this case, hotmail)?

i cant still see the picture here and what is happening/required to send a mail. i know what a MTA and a MDA is. but noone has explained this clearly so one could get the idea of how it all works.

would be great if someone could shed a light on this confusing area!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I would guess it isn't set up quite like you have said. Rather it would be a PHP SMTP library that is used and sendmail is not used. For this to work you put the log in information into php for the gmail account and it will communicate directly with it. I guess you could have sendmail use gmail as a smart host so it relays the email, but a PHP library would make more sense to me unless maybe you have a lot of different PHP applications.

If it wasn't like that (no authentication required), gmail would be running what is called an open relay which spammers would use to send crap loads of spam to people.

The reason to use gmail instead of sendmail itself to communicate with hotmail is because you don't have to deal with running an email server. They will make sure gmail users are allowed to send mail to places like hotmail without it being marked as spam. If you run send mail yourself, you are going to have to do all this work yourself.

Lastly, it is called a SMTP server (Simple Mail Transfer Protocol) server because that is what it does, it transfers email between servers (both sends and receives, but doesn't store). This is called an MTA (Mail Transfter Agent). What stores and lets email get their email is the MDA (Something like fetchmail). You can think of the MTA as the post office and the MDA as your mail box. Here is an overview of how email works on wikipedia.

share|improve this answer
    
hm i thought that php is using sendmail cause it use to be listed as the smtp server in php.ini. so you mean that i dont have to set up postfix just to send emails? i could send directly from php to gmail's smtp server? but then why are so many sending like this: php -> local smtp -> gmail -> receiver or like this: php -> local smtp -> receiver? –  ajsie Apr 5 '10 at 18:06
    
I don't know why (other than maybe all the preconfigured applications on the system can take advantage of it, someone else might have other reasons). There are plenty of libraries you can install which do that with PHP (Bypass the local SMTP server), smtplib would be one for python. –  Kyle Brandt Apr 5 '10 at 18:09
    
Also, googling the difference between an MTA and MDA might help clear up some of your confusion. –  Kyle Brandt Apr 5 '10 at 18:11
1  
PEAR::Mail and SSMTP are two PHP options. –  Kyle Brandt Apr 5 '10 at 18:18
    
@kyle: i have heard about the PEAR::Mail but never used it. so is this a pure script that sends your mail to gmail's smtp? i still dont understand how i could send a mail with gmail. assuming i've got a peter@gmail.com but the website has nothing to do with gmail.com. its a website with domain mypage.com. then doesnt all the mails sent to the users appear to come from peter@gmail.com if i use gmails smtp server? –  ajsie Apr 5 '10 at 18:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.