PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
SMTP with Gmail using mail.php , not load page for response
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail
View previous topic :: View next topic  
Author Message
Adalberto



Joined: 04 Apr 2008
Posts: 6

PostPosted: Fri Apr 04, 2008 3:37 pm    Post subject: SMTP with Gmail using mail.php , not load page for response Reply with quote

Hi , I using Mail.php and when I pass the parameter $host like :

$host = "ssl://smtp.gmail.com";
I got the error :
DEBUG: Recv: 220 mx.google.com ESMTP i19sm12798696wxd.33 DEBUG: Send: EHLO
localhost DEBUG: Recv: 250-mx.google.com at your service, [200.148.55.44]

DEBUG: Recv: 250-SIZE 28311552 DEBUG: Recv: 250-8BITMIME DEBUG: Recv:
250-AUTH LOGIN PLAIN DEBUG: Recv: 250 ENHANCEDSTATUSCODES

unable to authenticate to smtp server

But If I pass the parameter :
$host = "smtp.gmail.com";
I don't get error code and my page tryies to load and tryies ... , but nothing is loaded.

My code is :
<?php
require_once "Mail.php";

if($_POST[sub_login]=='Enviar')
{

$from = "user <at> XXXXX";

$to = "user <at> domain.com";
$subject = "Testando Código PHP";

$headers = array('From' => $from,'To' => $to,'Subject' => $subject);


$body = "Olá!\n\n Este é um teste de envio de email através de SMTP!";

$host = "ssl://smtp.gmail.com";

$port = 465;
$auth = "true";
$debug= "true";
$username = "[email protected]";

$password = "yyyyyy";

$params = array('host' => $host,'port' => $port ,'auth'=>$auth, 'debug' => $debug ,'username' => $username, 'password' => $password);
$smtp = Mail::factory('smtp',$params);

$mail = $smtp->send($to, $headers, $body);
}

?>
<html>
<body>
<?php

if(PEAR::isError($mail))
{
echo("<p>" . $mail->getMessage() . "</p>");
}
else
{
echo("<p>Email enviado com sucesso!!</p>");

}
?>
.... Here continues the code html inside file .php !!!
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Apr 04, 2008 4:34 pm    Post subject: Reply with quote

Please try to replace
Code:

$auth = "true";
$debug= "true";

by
Code:

$auth = true;
$debug= true;


Both parameters expect boolean values, and especially $auth is checked by an is_string() check.
Back to top
View user's profile Send private message
Adalberto



Joined: 04 Apr 2008
Posts: 6

PostPosted: Fri Apr 04, 2008 5:27 pm    Post subject: SMTP with Gmail using mail.php , not load page for response Reply with quote

Mark, thanks for your help. I'm learning how to use this forum, because it i have sended a private message to you. I'm sorry for that.

Anyway, I have changed my code like your sugestion and now I got the error :
DEBUG: Recv: 220 mx.google.com ESMTP c20sm9004473ana.13 DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mx.google.com at your service, [200.148.49.61] DEBUG: Recv: 250-SIZE 28311552 DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250-AUTH LOGIN PLAIN DEBUG: Recv: 250 ENHANCEDSTATUSCODES DEBUG: Send: AUTH LOGIN DEBUG: Recv: 334 VXNlcm5hbWU6 DEBUG: Send: YW9uYXNjaW1lbnRv DEBUG: Recv: 334 UGFzc3dvcmQ6 DEBUG: Send: IzEwMCVvY3A= DEBUG: Recv: 235 2.7.0 Accepted DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mx.google.com at your service, [200.148.45.64] DEBUG: Recv: 250-SIZE 28311552 DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250-AUTH LOGIN PLAIN DEBUG: Recv: 250 ENHANCEDSTATUSCODES DEBUG: Send: MAIL FROM: DEBUG: Recv: 530-5.5.1 Authentication Required. Learn more at DEBUG: Recv: 530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 c20sm9004473ana.13

unable to set sender to [[email protected]]

Look, this site is a portuguese site :
http://mail.google.com/support/bin/answer.py?answer=14257 c20sm9004473ana.13

I m lookig for answer in :
http://pear.php.net/manual/en/package.mail.mail.send.php

And in this site I found out this information :

smtp PEAR_MAIL_SMTP_ERROR_SENDER "Failed to set sender: from" Setting the sender address failed. Check the RFC-compliances of the sender address and the server connnectivity.


Anothers importants information are :
I'm using Iceweasel browers from mozilla.
I have this packages :
Desejado=U=Desconhecido/Instalar/Remover/aPagar/H=Manter
| status=Não/Instalado/arquiv.-Config./U=Descomp./Falhou-config/H=semi-inst.
|/ Erro?=(nenhum)/H=Mantido/precisa-Reinst./X=os dois problemas (status,Erro: maiúsculas=ruim)
||/ Nome Versão Descrição
+++-=========================-=========================-==================================================================
un php-auth-sasl <nenhuma> (nenhuma descrição disponível)
ii php-mail 1.1.6-2 PHP PEAR module for sending email
ii php-net-smtp 1.2.6-2 PHP PEAR module implementing SMTP protocol
ii php-net-socket 1.0.6-2 PHP PEAR Network Socket Interface module
ii php-pear 5.2.0-8+etch10 PEAR - PHP Extension and Application Repository

Maybe version is not correct ?
Thanks a lot.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Apr 04, 2008 5:34 pm    Post subject: Reply with quote

According to the error message, either your credentials (username / password) are wrong or the 'from' parameter has an invalid syntax (should be only '[email protected]', without anything else like names).

Another possibility is that you've tried to connect to often to Google's server. The suggestions on the mentioned Google help page might help in this case (=> captcha).
Back to top
View user's profile Send private message
Adalberto



Joined: 04 Apr 2008
Posts: 6

PostPosted: Fri Apr 04, 2008 6:06 pm    Post subject: Post subject: SMTP with Gmail using mail.php , not load page Reply with quote

Hi, in according with tihis message :

unable to set sender to [[email protected]]
and with this one :

smtp PEAR_MAIL_SMTP_ERROR_SENDER "Failed to set sender: from" Setting the sender address failed. Check the RFC-compliances of the sender address and the server connnectivity.

It was not possible to set the sender, but it's is very stranger because my user in gmail exist and I'm using this dclaration :

$from = "Adalberto <[email protected]>";

and I have tried : $from = "[email protected]";

But I got the same error .
I would like to know the correct form to pass the parameter : $host

$host = "ssl://smtp.gmail.com";
or
$host = "smtp.gmail.com";

In the firts form I got the error above, but in second form my page doesn't load !![/b]
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Apr 04, 2008 6:12 pm    Post subject: Re: Post subject: SMTP with Gmail using mail.php , not load Reply with quote

Adalberto wrote:
I would like to know the correct form to pass the parameter : $host

$host = "ssl://smtp.gmail.com";
or
$host = "smtp.gmail.com";


The second string is right. To enforce SSL, you'll have to use the right port value (which you're already seem to be doing).

It might help to add the following lines at the beginning of your script:
Code:

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'PEAR.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);


Maybe you'll get a more helpful message then.
Back to top
View user's profile Send private message
Adalberto



Joined: 04 Apr 2008
Posts: 6

PostPosted: Fri Apr 04, 2008 8:35 pm    Post subject: Post subject: SMTP with Gmail using mail.php , not load Reply with quote

I found out , this :

1st - ) When I passed $host ="ssl://smtp.gmail.com" and I erased my credentials ( username/password) from my .php file . I've got the error :
unable to authenticate to smtp server . It didn't get to autenticate in server.

But If pass my correct credentials with the same $host, I got the error :

" ...DEBUG: Recv: 235 2.7.0 Accepted DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mx.google.com at your service, [200.148.41.69] DEBUG: Recv: 250-SIZE 28311552 DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250-AUTH LOGIN PLAIN DEBUG: Recv: 250 ENHANCEDSTATUSCODES DEBUG: Send: MAIL FROM: DEBUG: Recv: 530-5.5.1 Authentication Required. Learn more at DEBUG: Recv: 530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 q57sm7681661wrq.5
MESSAGE :unable to set sender to [[email protected]]"


So, Does it correct to say that when I passed my correct credentials I have got to autenticate in smtp.gmail.com, but It's didn't get to SET the sender in e-mail and because it It's returned the error ?
The value sender is in $from="Adalberto <[email protected]>";

2nd-) If I pass $host="smtp.gmail.com" with correct credentials, the page doesn't load.

I think that in this situation I not getting to autenticate in smtp server.


Last edited by Adalberto on Fri Apr 04, 2008 8:43 pm; edited 1 time in total
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Apr 04, 2008 8:41 pm    Post subject: Re: Post subject: SMTP with Gmail using mail.php , not load Reply with quote

Adalberto wrote:
The value sender is in $from="Adalberto <[email protected]>";


Well, that's wrong, as I already wrote. Only an email address is allowed here.

Adalberto wrote:
2nd-) If I pass $host="smtp.gmail.com" with correct credentials, the page doesn't load.


Note the last user note on this page (it refers to the same problem):
http://pear.php.net/manual/en/package.mail.mail.send.php

You could debug your script (and the PEAR scripts) line by line to find the line that causes this "hanging" problem.
Back to top
View user's profile Send private message
Adalberto



Joined: 04 Apr 2008
Posts: 6

PostPosted: Fri Apr 04, 2008 8:59 pm    Post subject: Post subject: SMTP with Gmail using mail.php , not load Reply with quote

Mar, thanls again, but the same error occurs.

I have changed the parameter $from="[email protected]";
But I have got :
MESSAGE :unable to set sender to [[email protected]]

And the other "hanging" error contines too.

You wrote:
You could debug your script (and the PEAR scripts) line by line to find the line that causes this "hanging" problem.

Could you give me a hint to do that ?
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Apr 04, 2008 9:10 pm    Post subject: Re: Post subject: SMTP with Gmail using mail.php , not load Reply with quote

Adalberto wrote:
You wrote:
You could debug your script (and the PEAR scripts) line by line to find the line that causes this "hanging" problem.

Could you give me a hint to do that ?


Well, you add some debug code (like die('test')Wink to your own code and the files from the Mail package (and probably Net_SMTP and Net_Socket) to different places. This way you'll see which parts are reached, and where PHP stops working. If you have a real debugger (like in Zend Studio) this is even easier.
Back to top
View user's profile Send private message
Adalberto



Joined: 04 Apr 2008
Posts: 6

PostPosted: Sat Apr 05, 2008 11:13 pm    Post subject: SMTP with Gmail using mail.php , not load Reply with quote

Hi.
Definitely I have to pass the parameter $host="ssl://smtp.gmail.com"; I already wrote it.

When I executing my file .php with Mail.php, I'm getting the error :

from getMessage() method I get :

MESSAGE :Failed to set sender: [email protected] [SMTP: Invalid response code received from server (code: 530, response: 5.5.1 Authentication Required. Learn more at 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 36sm8707536aga.17)]


from getCode() method : 10004
Back to top
View user's profile Send private message
chifliiiii



Joined: 02 May 2008
Posts: 3

PostPosted: Tue May 20, 2008 7:00 pm    Post subject: Reply with quote

Any luck with these? i get the same error
DEBUG: Recv: 220 mx.google.com ESMTP d6sm350303fga.2 DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mx.google.com at your service, [87.218.227.97] DEBUG: Recv: 250-SIZE 28311552 DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250-AUTH LOGIN PLAIN DEBUG: Recv: 250 ENHANCEDSTATUSCODES DEBUG: Send: AUTH LOGIN DEBUG: Recv: 334 VXNlcm5hbWU6 DEBUG: Send: Y2hpZmxpQGdtYWlsLmNvbQ== DEBUG: Recv: 334 UGFzc3dvcmQ6 DEBUG: Send: Y2hpZmxpMjk4NA== DEBUG: Recv: 235 2.7.0 Accepted DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mx.google.com at your service, [87.218.227.97] DEBUG: Recv: 250-SIZE 28311552 DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250-AUTH LOGIN PLAIN DEBUG: Recv: 250 ENHANCEDSTATUSCODES DEBUG: Send: MAIL FROM: DEBUG: Recv: 530-5.5.1 Authentication Required. Learn more at DEBUG: Recv: 530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 d6sm350303fga.2

it seems like the auth is not working . I also tried on another email host and i get a diferent error telling me that i need to use the pop before to check that is a secure connection.
I searched all over the net so i think i got the correct code.
Code:
// FUNCION DE ENVIO DE EMAILZ
function mandaremail($de,$para,$sujeto,$mensaje){
require_once ("Mail/mime.php");
 require_once "Mail.php";




$headers['From']=$de;
 $headers['To'] =$para;
 $headers['Subject']= $sujeto;
 $crlf = "\n";
$mime = new Mail_mime($crlf);
$parametros['host']='ssl://smtp.gmail.com';
$parametros['auth']=true;
$parametros['port']=465;
$parametros['username']='chifli*****';
$parametros['password']='*******';
$parametros['debug']=true;
$parametros['persist']=true;
$smtp =& Mail::factory('smtp',$parametros);
$mime->setHTMLBody($mensaje);
$body= $mime->get();
$headers=$mime->headers($headers);
$mail=$smtp->send($to, $headers, $body);
print 'debug2';
if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 }
}   
Back to top
View user's profile Send private message
koyama



Joined: 17 Mar 2009
Posts: 1

PostPosted: Tue Mar 17, 2009 10:02 pm    Post subject: Reply with quote

Sorry for digging up this old thread which I found via Google.

I had similar problems. It turned out that my web host didn't have Net_SMTP. So I downloaded the package from PEAR and included it manually.

This may seem like a stupid advice, but on a shared web hosting you can check in you have Net_SMTP like this:

Code:

<?php
$x = new Net_SMTP();
var_dump($x);
?>


If you get a fatal error, there you have the problem.
Back to top
View user's profile Send private message
duongld



Joined: 02 May 2009
Posts: 1

PostPosted: Sat May 02, 2009 3:12 am    Post subject: Reply with quote

1) edit the file /usr/share/pear/Net/SMTP.php
2) at the end of function auth(), comment out the call to _negotiate()

I had the same problem and this fix my problem.
Back to top
View user's profile Send private message
jtb2468



Joined: 28 May 2009
Posts: 1

PostPosted: Thu May 28, 2009 5:36 pm    Post subject: Reply with quote

I found this on Google as well.

Koyama's solution fixed my problem. I ran the script that Koyama posted and got the fatal error. I wasn't sure how to install the Net_SMTP PEAR package. If you have a similar problem you can install it like this from the terminal:

Code:
# pear install Net_SMTP


If you are using Ubuntu, you will need to use sudo to run that command.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement