Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pear email unable to connect to Gmail SMTP

Posted on 2010-11-28
6
Medium Priority
?
145 Views
Last Modified: 2016-05-13
The following PHP code yeilds this error message:  "Your message was not sent: Failed to set sender: Test2@gmail.com [SMTP: Failed to write to socket: not connected (code: -1, response: )]"

<?php

include("/usr/lib/php/Mail.php");
/* mail setup recipients, subject etc */
$recipients = "Test1@yahoo.com";
$headers["From"] = "Test2@gmail.com";
$headers["To"] = "Test1@yahoo.com";
$headers["Subject"] = "Pear Mail";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "smtp.gmail.com:Test2";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "Test2@gmail.com";
$smtpinfo["password"] = "XXXXX";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);

$result = $mail_object->send($recipients, $headers, $mailmsg);
        if($result === 1)
        {
          echo("Your message has been sent!");
        }
        else
        {
          echo("Your message was not sent: " . $result);
        }

?>

Any ideas what's going on here?

Thanks in advance,
Sailorjkg
0
Comment
Question by:sailorjkg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 2

Expert Comment

by:arkod
ID: 34226209
The smtp server hostname is wrong
$smtpinfo["host"] = "smtp.gmail.com:Test2"; change it to --> $smtpinfo["host"] = "smtp.gmail.com";

Further by looking at your code I am not sure whether you can manage to send and receive mails by using test2@gmail.com and test2@yahoo.com unless you have an actual account with these usernames both on Gmail and Yahoo.

Additionally , you may need ssl support for sending mails through gmail. As port 587 smpt runs over tls.
0
 

Author Comment

by:sailorjkg
ID: 34226272
The error message that appears when the ":Test2" is deleted from the host designation is "Your message was not sent: 1".  All the email addresses listed in the sample code are fictitious.  I understood the PEAR defaults to TLS not SSL.  According to the Gmail port 587 is the TLS accessible port.  Port 465 is the SSL port.  

Is there a change in syntax for addressing the SSL port?

Thanks for the help.  Seems like there is some simplification of the error message.

Sailorjkg
0
 

Accepted Solution

by:
sailorjkg earned 0 total points
ID: 34226319
Just changed the port to 465 and prefaced the host line with "ssl://".  The error message "Your message was not sent: 1" remains, but the email was actually sent from Gmail and received at Yahoo.
0
 
LVL 6

Expert Comment

by:nagyistvan
ID: 34459951
have you tried adding
$smtpinfo["debug"]  = true;

Open in new window

 to check where the issue might hide?
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question