Avatar of kiwistag
Flag for New Zealand asked on

Defaulting a GMail from Alias instead of a username with PEAR mail & PHP

As part of a site I've set the from field as an e-mail alias/nickname attached to a gmail apps account (gmail on a domain name address).
I've got the example here working on my site but it exposes the main account rather than the alias.

$from = "bookings@domain.com"
$username = "employee@domain.com"

For some reason it doesn't default the e-mail from field as the $from variable to an e-mail sent to someone, it sends the $username instead...

Any ideas on how to fix this or is it something stuck with gmail / Google Apps?
PHPApache Web Server

Avatar of undefined
Last Comment

8/22/2022 - Mon
Ray Paseur

Please show us a short demonstration script that is having this issue.  Blot out the password, but leave everything else exactly as you have it.  Thanks, ~Ray

Note that fwf.net & fwf.org are modified and that both domains are registered under the same google apps/gmail domain account. (i.e. e-mailing username@fwf.net goes to username@fwf.org) and that the nicknames/aliases are in place. fwf.org is the default domain.


$subj="E-Mail Subject here";
$info="Thank you for submitting your REQUEST for the 2012 ....
Please click on the link below (or copy it to your browser) to continue to the next step.

Until you do this - your full request WILL NOT be complete.

Please also ensure you read the document at the web address below. Note that in this case the postage application does not count.

Kind regards,


	require_once "/usr/share/pear/Mail.php";

$from = "alias@fwf.net";
$to = $destemail;
$subject = $subj;
$body = $info;

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "username@fwf.org";
$password = "*password*";

$headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
  'port' => $port,
  'auth' => true,
  'username' => $username,
  'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
	echo("<p>" . $mail->getMessage() . "</p>");
} else {
	echo("<p>Message successfully sent!</p>");

Open in new window


Weirdly enough while playing with the code making only VERY minor tweaks it worked - I've redone some of it to support MAPI.
However... After finishing the MAPI code it reverted again! @#*%&#@&
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Not the best solution but worth considering.