I want to send an email from A to B,with HEADER and CONTENT through gmail.
How to do that by PHP?
I've specified the FROM([email protected]),but when I receive the email,it's still from my gmail account([email protected]).
$mail->From = "[email protected]"; $mail->FromName = "Mailer"; $mail->AddAddress("[email protected]", "Josh Adams");// name is optional $mail->AddReplyTo("[email protected]", "Information");
How do I change the FROM part?
In the "Send mail as" section, click Add another email address. Enter your name and the address you want to send from. Send verification. For school or work accounts, enter the SMTP server (for example, smtp.gmail.com or smtp.yourschool.edu) and the username and password on that account.
1) Go to Accounts and Imports tab from Gmail settings page. 2) Click on 'Send mail from another address' button found user Send mail as section. 3) Follow the Gmail's instruction and you are done.
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:
====
It was suggested that GMail does allow sending via different addresses. As far as I can tell, this is for sending via the GMail wep app, and utilises your existing external SMTP server, which is not relevant to the original question.
====
Seeing as this is still getting a trickle of votes. A quick update.
Google have withdrawn their free GMail for domains. There are plenty of other free services around. One of note is Mandrill - a one-to-one email service intended for transactional emails (e.g. ecommerce orders etc.). It's ran by MailChimp, who pretty much know all there is to know about sending email at volume. They also give you 12k/month free, which is rather nice.
This question and correct answer may be relevant:
When using Gmail for SMTP, can you set a different "from" address?
Gmail requires you to validate From addresses before sending mail as that email address. So you need to add a new sender in your personal gmail account and validate it.
Doing so will allow you to authenticate with [email protected] and send email from [email protected]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With