PHPMailer using GMAIL SMTP with multiple GMAIL accounts for multiple virtual hosts
I have already set up PHPMailer and it already worked with one domain, using a gmail account for the SMTP service.
When I wanted to use PHPMailer, likewise, with a different Gmail account (for a different virtual host), it would still send it from the same Gmail acccount because that's what is identified as "the email address" of the server (of the server on which severe virtual hosts run)
my question is, what do you need to have in order to be able to be able to use another Gmail account?
another IP address? or another server? or?
and what will be the ultimate limitations in terms of the FROM ADDRESS if you only have one IP address and one server?
Gmail does not mind you using multiple accounts from the same IP, so long as you authenticate correctly for each. That is, there is no fixed relationship between the server you're sending from and the gmail account you use.
The one thing that will be the same across accounts is the EHLO hostname (set via PHPMailer's
Heloproperty, if it can't be derived automatically), because you really want that to resolve backwards as well as forwards in DNS, and you can't do that with multiple names at once - but that has no effect on authentication.
There's no need for the actual hostname of the server to be related to the domain you're sending from, so you can safely say:
$mail->From = 'email@example.com'; $mail->Username = 'firstname.lastname@example.org';
and then, in another vhost:
$mail->From = 'email@example.com'; $mail->Username = 'firstname.lastname@example.org';
If you watch the SMTP conversation (
SMTPDebug = 2), both will have the same EHLO name (which might be a generic
host.example.com), but then use different authentication and
MAIL FROMaddresses (the SMTP source address, which may be different from what's in the message's from header if you make use of the
Senderproperty, but either way it will be turned into a
return-pathheader by the receiver) for sending the messages.