Search code examples
phpsmtpgmailpearpear-mail

php pear mail not modifying 'from' when using google apps gmail


I have google apps setup for one of my site's emails, thus making the site's built-in email routing useless when doing things from the web. What i need to do , is have it use ssl/smtp to connect to the google apps setup. To accomplish this, I've used PEAR Mail and mime (for the HTML contents). The messages get sent without an issue... the ONLY problem i'm having, is that the 'From' header isn't being saved across transmission. Instead, the account email is in the 'from' header.

The accounts exist on the webserver's end (which means nothing since its all going through google), and i've added aliases to my gmail apps administration end. But no matter what i do, its not changing the 'from'.

Is this just something i'm going to run into when using a single account with google apps' gmail? (--forced 'from' from the account name?)

Thanks

--for those who were wondering, here is an example function for the mail sending:

function pearMail($from, $fromTitle, $to, $subject, $text, $html)
{
require_once "Mail.php";
require_once('Mail/mime.php');

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "[email protected]";
$password = "PASSWORD";

$headers = array ('From' => $from,
    'Return-Path' => '-do not reply-',
'To' => $to,
'Subject' => $subject);     
$crlf = "\n";
// Creating the Mime message
    $mime = new Mail_mime($crlf);
// Setting the body of the email
    $mime->setTXTBody($text);
    $mime->setHTMLBody($html);

    $body = $mime->get();
    $headers = $mime->headers($headers,true);
// Sending the email
    $mail =& Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail->send($to, $headers, $body);

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

Solution

  • See the google help on changing From::

    The custom 'From:' feature works only if you already own the account linked to the alternate address. To send mail with a different Gmail username, you must first sign up for that address.