| View previous topic :: View next topic |
| Author |
Message |
Adalberto
Joined: 04 Apr 2008 Posts: 6
|
Posted: Fri Apr 04, 2008 3:37 pm Post subject: SMTP with Gmail using mail.php , not load page for response |
|
|
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 = "xx@gmail.com";
$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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Apr 04, 2008 4:34 pm Post subject: |
|
|
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 |
|
 |
Adalberto
Joined: 04 Apr 2008 Posts: 6
|
Posted: Fri Apr 04, 2008 5:27 pm Post subject: SMTP with Gmail using mail.php , not load page for response |
|
|
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 [aonascimento@gmail.com]
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Apr 04, 2008 5:34 pm Post subject: |
|
|
According to the error message, either your credentials (username / password) are wrong or the 'from' parameter has an invalid syntax (should be only 'user@example.com', 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 |
|
 |
Adalberto
Joined: 04 Apr 2008 Posts: 6
|
Posted: Fri Apr 04, 2008 6:06 pm Post subject: Post subject: SMTP with Gmail using mail.php , not load page |
|
|
Hi, in according with tihis message :
unable to set sender to [aonascimento@gmail.com]
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 <aonascimento@gmail.com>";
and I have tried : $from = "aonascimento@gmail.com";
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Apr 04, 2008 6:12 pm Post subject: Re: Post subject: SMTP with Gmail using mail.php , not load |
|
|
| 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 |
|
 |
Adalberto
Joined: 04 Apr 2008 Posts: 6
|
Posted: Fri Apr 04, 2008 8:35 pm Post subject: Post subject: SMTP with Gmail using mail.php , not load |
|
|
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 [aonascimento@gmail.com]"
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 <aonascimento@gmail.com>";
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Apr 04, 2008 8:41 pm Post subject: Re: Post subject: SMTP with Gmail using mail.php , not load |
|
|
| Adalberto wrote: | | The value sender is in $from="Adalberto <aonascimento@gmail.com>"; |
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 |
|
 |
Adalberto
Joined: 04 Apr 2008 Posts: 6
|
Posted: Fri Apr 04, 2008 8:59 pm Post subject: Post subject: SMTP with Gmail using mail.php , not load |
|
|
Mar, thanls again, but the same error occurs.
I have changed the parameter $from="aonascimento@gmail.com";
But I have got :
MESSAGE :unable to set sender to [aonascimento@gmail.com]
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 |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Apr 04, 2008 9:10 pm Post subject: Re: Post subject: SMTP with Gmail using mail.php , not load |
|
|
| 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') 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 |
|
 |
Adalberto
Joined: 04 Apr 2008 Posts: 6
|
Posted: Sat Apr 05, 2008 11:13 pm Post subject: SMTP with Gmail using mail.php , not load |
|
|
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: aonascimento@gmail.com [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 |
|
 |
chifliiiii
Joined: 02 May 2008 Posts: 3
|
Posted: Tue May 20, 2008 7:00 pm Post subject: |
|
|
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 |
|
 |
|