When I couldn't get yours to work, I went internet surfing...now that I've learned a few things, I am back with your script. But...no joy. I got the following failure message:
send failure: object(PEAR_Error)#4 (8).
Debug was on and it kicked out a whole slew of errors including a failure to connect at prot 587
send failure: object(PEAR_Error)#4 (8) { ["error_message_prefix"]=> string(0) "" ["mode"]=> int(1) ["level"]=> int(1024) ["code"]=> int(10001) ["message"]=> string(117) "Failed to connect to smtp.gmail.com:587 [SMTP: Failed to connect socket: Connection timed out (code: -1, response: )]" ["userinfo"]=> NULL ["backtrace"]=> array(4) { [0]=> array(6) { ["file"]=> string(51) "/hsphere/shared/apache/libexec/php5ext/php/PEAR.php" ["line"]=> int(533) ["function"]=> string(10) "PEAR_Error" ["class"]=> string(10) "PEAR_Error" ["type"]=> string(2) "->" ["args"]=> array(5) { [0]=> string(117) "Failed to connect to smtp.gmail.com:587
If you have time, here's another look. Hope we can solve the problem. This sounds like a very good tool for me.
// code that follows requires you to have PEAR mail installed
try {
// require the pear Mail module
require_once "Mail.php";
// this is the message you want to send
$message = "Yo bro how you doin?";
$params = array(
"host" => "smtp.gmail.com",
"port" => 587,
"auth" => TRUE,
"username" => "robkirUserName",
"password" => "robkirPassword",
"debug" => TRUE
);
$smtp = Mail::factory('smtp', $params);
if (PEAR::isError($smtp)){
throw new Exception("Unable to create pear MAIL object");
}
$headers = array(
"From" => "robkir@gmail.com",
"Sender" => "robkir@gmail.com",
"Reply-to" => "robkir@gmail.com"
);
$send_result = $smtp->send("recipient@example.com.com", $headers, $message);
if ($send_result !== TRUE){
echo "send failure:\n";
var_dump($send_result);
echo "\n\n";
}
echo "\n\nTHAT IS ALL\n\n";
} catch (Exception $e) {
echo "error:" . $gpg->geterror();
die("Exception:" . $e->getMessage());
}
My gmail username doesn't include the @gmail, but I tried that variation, just in case.
Interesting stuff, thanks for turning me on to it.
robkir