The Little Guy Posted September 26, 2010 Share Posted September 26, 2010 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 = '[email protected]'; $headers['From'] = '[email protected]'; $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? Quote Link to comment https://forums.phpfreaks.com/topic/214414-pearmail/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2010 Share Posted September 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214414-pearmail/#findComment-1115804 Share on other sites More sharing options...
The Little Guy Posted September 26, 2010 Author Share Posted September 26, 2010 Okay, if i add 'auth' to the params list, and set it to true, I still get the same message. I assumed that is what you were telling me I needed to do. Was I wrong? Quote Link to comment https://forums.phpfreaks.com/topic/214414-pearmail/#findComment-1115805 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2010 Share Posted September 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214414-pearmail/#findComment-1115808 Share on other sites More sharing options...
The Little Guy Posted September 26, 2010 Author Share Posted September 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214414-pearmail/#findComment-1115816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.