A: 

Take a look at http://swiftmailer.org/. And why exactly do you want to use GMail?

Ignas R
Because I don't want to set up a MTA myself
Shore
A: 

Or check phpmailer.org - an awesome email library. Not sure about Letters tho.

Christian
Actually, its site is at http://phpmailer.worxware.com/.
Ignas R
Ah woops, yeah of course it is.
Christian
+1  A: 

Unlike everyone else, I'll take the plunge and make the assumption that by letters you mean emails...

But I'm not sure what you are getting at when you mention that it should include "Headers and Content". Do you want to forward emails? Do you want the emails from A to appear as though they came from B's gmail account in the headers? Are you building some sort of gmail client?

The easiest way to send an email with PHP is with the mail function. This example comes straight from their documentation:

$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

If you want the headers to appear from A's gmail and not to simply change the from/reply to part, you'd have to use gmail as the SMTP server. I don't know if you can set that at the script level.

Anthony
It seems that "From: [email protected]" is not working now.
Shore
Did you replace [email protected] with the email address that you are actually wanting to send from?
Anthony
No,I think when I receive the email,should be from "[email protected]",but in fact it shows it's from "[email protected]" which is my gmail account.
Shore
I just sent an email to you with PHP where I made the FROM as your email, did it work?
Anthony
and another one where I made the `FROM` as `[email protected]`.
Anthony
Could you send me your library and demo code?Seems the version I'm using doesn't work:(
Shore
BTW,are you using gmail?As iAn said below,this can't be achieved with gmail.
Shore
I am just using the native PHP mail function and the code in my answer. I copied it and changed "[email protected]" to your email address. Which version of PHP are you using?
Anthony
So you aren't sending from gmail.I don't want to install postfix or equivalent,and the default "send" of linux is not scalable,so I decided to use a third party Mail Transfer Agent,like gmail.
Shore
I am not using gmail as the SMTP, no. I'm using a PHP script which is hosted on my school server account. If you just want the email to have the FROM line as being from "[email protected]", you don't have to use gmail. Gmail doesn't change the FROM line of incoming mails, only outgoing. Do you need it to really come from gmail or just have it appear that way in the FROM line?
Anthony
Other third-party Mail Transfer Agent like gmail are all acceptable.Do you know which public MTA doesn't have such restrictions?
Shore
If you click on the `show orignal message` link on the email I sent you, you'll see the full Headers, which reflect the SMTP server (ie my server) and any other server that handled the message before it got to you. But this should only be a concern if you are spamming (which I hope you aren't) or if you are afraid that the recipient will look at the full headers and see something you don't want them to.
Anthony
So are you trying to send emails using PHP locally on your own computer? Not on hosted server? I don't understand why things like MTAs and postfix and MTA restrictions are part of the equation. Sign up for a good hosting plan, put the example script I used in my original answer in the publishing directory, and go to the script in your browser. You'll get an email with what you want, I'm sure.
Anthony
And not to sound sleazy, but a vote up on my answer would sure make this hour long conversation seem worth it.
Anthony
OK,I've given you the vote:)But you didn't understand me.I don't want to send from my hosting environment...
Shore
What I am seeking of is a public and free MTA
Shore
postfix, sendmail, and exim are all public and free and control (according to wikipedia) over half of all emails sent in the world. It still sounds like you want an SMTP sever to me, but I'm way over my head.
Anthony
Yes,I want a PUBLIC and FREE SMTP server,I don't want to setup it by myself.
Shore
Nor has it preinstalled in my hosting environment
Shore
one really cool mta I know of is zimbra. but if you don't want a hosting environment, I'm not sure you'd want an exchange-like solution either.
Anthony
Well, if I'm not mistaken, what you want then is an SMTP Proxy Server. Based on my hunting around on google, you get the same issues with a free mail proxy that you do with free proxies in general, which is they are crowded and thus slow, unreliable, and possibly unsecure. If it was me, and I absolutely had to use an SMTP server that wasn't part of my host, I'd pay the 10-20 bucks per month to know it was reliable. Even if you could do it over Google, your account would be flagged most likey if it was sending 1000s of emails but never recieving.
Anthony
Haha,you got it!I don't want to pay those bucks..
Shore
+6  A: 

The short answer - you can't.

Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.

The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.

You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.

If you are intent on using gmail then you could:

iAn
Other third-party Mail Transfer Agent like gmail are all acceptable.Since gmail has such limitations,could you recommend another one?
Shore
A: 

If the reason you want to use gmail is because you don't want to set up an MTA (the reason you stated in a comment to this answer), you have 2 options:

  1. If the web server is at your home/work place; use your ISP's smtp-server
  2. If the web server is at a dedicated hosting center, ask them what smtp-server to use.
Espo
No,a public and free MTA is better:(
Shore
Better in what sense? Why do you not want to use the ISP's SMTP-server?
Espo
I don't want to pay extra bucks:)
Shore
What ISP do you use? I have never heard of one that charges you to use their SMTP server?
Espo