Jump to content

PEAR:Mail


The Little Guy

Recommended Posts

I am trying to send an email to my gmail account using Mail SMTP.

 

With the following code:

<?php
include 'incl/php/Mail.php';

$recipients = 'xxxxxxxx@gmail.com';

$headers['From']    = 'no-reply@newzstand.us';
$headers['To']      = $recipients;
$headers['Subject'] = 'Test message';
$headers['Date'] = date('r', time());
$headers['Message-Id'] = '<'.  microtime(true).'@newzstand.us>';

$body = 'Test message';

$domain = preg_replace("/.*@([^@]*)/", '\1', $recipients);
$mxrr = getmxrr($domain, $mxhosts);
$params['host'] = $mxhosts[0];
$params['localhost'] = 'mail.newzstand.us';
$params['username'] = 'no-reply';
$params['password'] = 'xxxxxxx';

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $params);

$send = $mail_object->send($recipients, $headers, $body);

if (PEAR::isError($send)){
echo $send->getMessage();
}else{
echo 'No error';
}
?>

 

I get the following message:

Failed to connect to alt2.gmail-smtp-in.l.google.com:25 [sMTP: Failed to connect socket: Connection refused (code: -1, response: )]

 

Why is Gmail refusing me?

Link to comment
Share on other sites

You are getting the mx record of the recipient domain and are attempting to send directly from a php script to that mail sever, but you are not using SMTP Authentication.

 

Unless you were sending to a mail server that is an "open relay" (no relaying restrictions in place), you would need to use SMTP Authentication to get it to accept an email directly from a php script that is not on a server that the mail server has been configured to trust.

Link to comment
Share on other sites

Do you actually have a mail server at your web host that you are trying to use as the sending mail server or are you trying to send directly to your mail box on a gmail server?

 

To use SMTP Authorization for your gmail account, you would actually need to use the SMTP server/port as listed at this link - http://mail.google.com/support/bin/answer.py?hl=en&answer=13287

 

The address you get from the MX records would only be used when one mail server contacts another mail server.

Link to comment
Share on other sites

basically I want to send mail, then get the status of whether the message was sent, if the host exist, etc.

 

I don't want to use the mail function because that only tells me if the message was successfully sent to the mail server to be sent on its way, not that the message has actually been sent and received by the recipient.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.