sEnte Posted October 31, 2016 at 11:50 AM Report #600056 Posted October 31, 2016 at 11:50 AM (edited) Boas pessoal. Estive aqui a tentar criar uma pequena aplicação em PHP e usei a framework Slim. É uma coisa muito básica onde o utilizador pode-se registar, e a quando do registo supostamente deveria receber um email a dizer que se registou. Ora muito bem, aqui é que estou com dificuldades. O utilizador é criado com sucesso, mas o email não vai. A função send é a seguinte <?php public function send($template, $data, $callback) { $message = new Message($this->mailer); $this->view->appendData($data); $message->body($this->view->render($template)); call_user_func($callback, $message); $this->mailer->send(); var_dump($this->mailer->send()); die(); } ?> Quando adicionei o var_dump o erro que dá é bool(false) Como "tira teimas" criei um outro ficheiro fora deste projeto e meti o mais básica código para enviar emails (Obviamente alterei os emails para colocar aqui) <?php ini_set("SMTP","smtp.gmail.com" ); $Name = "Sender"; $email = "sender@mail.com"; $recipient = "receiver@mail.com"; $mail_body = "The text for the mail..."; $subject = "Subject for reviever"; $header = "From: ". $Name . " <" . $email . ">\r\n"; mail($recipient, $subject, $mail_body, $header); ?> no meu php.ini tenho a seguinte configuração para a parte do mail [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = smtp.gmail.com ; http://php.net/smtp-port smtp_port = 587 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = me@example.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(). ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename mail.add_x_header = On ; The path to a log file that will log all mail() calls. Log entries include ; the full path of the script, line number, To address and headers. ;mail.log = ; Log mail to syslog (Event Log on Windows). ;mail.log = syslog quando executo o mail.php aparece-me este erro Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. m194sm24421424wmg.11 - gsmtp in C:\WebServer\Apache24\htdocs\html\www\mail.php on line 12 Instalei PHP, MySQL, Apache e phpMyAdmin tudo em separado. Podem dar uma ajuda? Edited October 31, 2016 at 11:52 AM by sEnte "If It Ain't Broke, Break it and build something Cooler!" Unknown
tiago.f Posted October 31, 2016 at 12:19 PM Report #600057 Posted October 31, 2016 at 12:19 PM (edited) Oi, na tua configuração tens: smtp_port = 587 o que está apontar para a porta que usa encriptação TLS. Como o teu php não está a usar encriptação, recebes o tal erro 530. Se mudares para smtp_port = 25 ou comentares a linha, já que 25 é o valor default, já deve funcionar. (ou rebentar mais à frente :)) Edited October 31, 2016 at 12:19 PM by tiago.f
sEnte Posted October 31, 2016 at 12:27 PM Author Report #600058 Posted October 31, 2016 at 12:27 PM Voltei ás definições iniciais no php.ini SMTP = localhost e smtp_port = 25 e apaguei o ini_set() no ficheiro mail.php. Como esperado deu outro erro. Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\WebServer\Apache24\htdocs\html\www\mail.php on line 10 Assim que adicionei o ini_set ao ficheiro mail.php deu novamente o mesmo erro. "If It Ain't Broke, Break it and build something Cooler!" Unknown
tiago.f Posted October 31, 2016 at 01:35 PM Report #600059 Posted October 31, 2016 at 01:35 PM mas agora tens um erro diferente Failed to connect to mailserver at "localhost" port 25 O teu servidor de email está bem configurado?
sEnte Posted October 31, 2016 at 02:30 PM Author Report #600061 Posted October 31, 2016 at 02:30 PM é nesse aspeto que estou aqui a pedir ajuda. configurar isso. 🙂 "If It Ain't Broke, Break it and build something Cooler!" Unknown
tiago.f Posted October 31, 2016 at 03:11 PM Report #600063 Posted October 31, 2016 at 03:11 PM Nesse caso sugiro abrires um tópico que esteja no sub-forum certo. Este é o de php.. (e não consigo ajudar)
sEnte Posted October 31, 2016 at 04:27 PM Author Report #600065 Posted October 31, 2016 at 04:27 PM E esse sub-tópico é? Não sei onde colocar "If It Ain't Broke, Break it and build something Cooler!" Unknown
Rui Carlos Posted October 31, 2016 at 06:30 PM Report #600066 Posted October 31, 2016 at 06:30 PM Assim à primeira vista, faltam-te os dados de autenticação, que são necessários para conseguires usar o Gmail como servidor de SMTP. Em todo o caso, não deve ser essa a causa do erro que estás a obter. Verifica se o PHP tem o SSL/TLS a funcionar. Depois, experimenta mudar a propriedade SMTP para tls://smtp.gmail.com (mantendo o porto 587). Quando a ligação funcionar, terás então de adicionar os dados de autenticação (penso que as propriedades a usar são auth_username e auth_password). Certifica-te também que a conta Gmail que usas tem o SMTP a funcionar. Rui Carlos Gonçalves
sEnte Posted October 31, 2016 at 06:50 PM Author Report #600067 Posted October 31, 2016 at 06:50 PM Começando... Reparei que no httpd.conf o # Secure (SSL/TLS) connections Include conf/extra/httpd-ssl.conf estava comentado, logo não estava funcional. LoadModule ssl_module modules/mod_ssl.so também estava comentado. Tentei reiniciar o Apache e dá erro tendo essas duas opções ativas, através de tentativa e erro dá-me erro quando tenho o Include conf/extra/httpd-ssl.conf ativo. Fui procurar o httpd.ssl e no inicio tinha lá isto # Required modules: mod_log_config, mod_setenvif, mod_ssl, # socache_shmcb_module (for default value of SSLSessionCache) fui ver se estavam ativos ou não e à exceção do último estava tudo ativo. "If It Ain't Broke, Break it and build something Cooler!" Unknown
sEnte Posted November 1, 2016 at 03:41 PM Author Report #600073 Posted November 1, 2016 at 03:41 PM (edited) No registo de erros aparece isto Quote [Mon Oct 31 20:00:16.022479 2016] [mpm_winnt:notice] [pid 3900:tid 552] AH00422: Parent: Received shutdown signal -- Shutting down the server. [Mon Oct 31 20:00:18.023943 2016] [mpm_winnt:notice] [pid 4420:tid 500] AH00364: Child: All worker threads have exited. [Mon Oct 31 20:00:18.051911 2016] [mpm_winnt:notice] [pid 3900:tid 552] AH00430: Parent: Child process 4420 exited successfully. [Mon Oct 31 20:00:20.997012 2016] [ssl:warn] [pid 1564:tid 556] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] [Mon Oct 31 20:00:20.998011 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00455: Apache/2.4.23 (Win64) PHP/7.0.11 OpenSSL/1.0.2j configured -- resuming normal operations [Mon Oct 31 20:00:20.998011 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00456: Apache Lounge VC14 Server built: Jul 1 2016 11:43:51 [Mon Oct 31 20:00:20.998011 2016] [core:notice] [pid 1564:tid 556] AH00094: Command line: 'C:\\WebServer\\Apache24\\bin\\httpd.exe -d C:/WebServer/Apache24' [Mon Oct 31 20:00:21.006017 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00418: Parent: Created child process 11416 [Mon Oct 31 20:00:23.481769 2016] [ssl:warn] [pid 11416:tid 488] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] [Mon Oct 31 20:00:23.489775 2016] [mpm_winnt:notice] [pid 11416:tid 488] AH00354: Child: Starting 64 worker threads. [Mon Oct 31 20:00:34.345861 2016] [:error] [pid 11416:tid 1080] [client ::1:63686] PHP Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\\WebServer\\Apache24\\htdocs\\html\\www\\mail.php on line 11 [Mon Oct 31 21:58:00.390144 2016] [:error] [pid 11416:tid 1080] [client ::1:49686] PHP Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\\WebServer\\Apache24\\htdocs\\html\\www\\mail.php on line 11 [Tue Nov 01 15:40:13.835164 2016] [:error] [pid 11416:tid 1080] [client ::1:61570] PHP Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\\WebServer\\Apache24\\htdocs\\html\\www\\mail.php on line 11 Voltei a olhar e [Tue Nov 01 15:40:13.835164 2016] [:error] [pid 11416:tid 1080] [client ::1:61570] PHP Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\\WebServer\\Apache24\\htdocs\\html\\www\\mail.php on line 11 [Tue Nov 01 15:43:43.823313 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00424: Parent: Received restart signal -- Restarting the server. [Tue Nov 01 15:43:44.263621 2016] [ssl:warn] [pid 1564:tid 556] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] [Tue Nov 01 15:43:44.263621 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00455: Apache/2.4.23 (Win64) PHP/7.0.11 OpenSSL/1.0.2j configured -- resuming normal operations [Tue Nov 01 15:43:44.263621 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00456: Apache Lounge VC14 Server built: Jul 1 2016 11:43:51 [Tue Nov 01 15:43:44.263621 2016] [core:notice] [pid 1564:tid 556] AH00094: Command line: 'C:\\WebServer\\Apache24\\bin\\httpd.exe -d C:/WebServer/Apache24' [Tue Nov 01 15:43:44.269625 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00418: Parent: Created child process 5284 [Tue Nov 01 15:43:44.964116 2016] [ssl:warn] [pid 5284:tid 488] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache] [Tue Nov 01 15:43:44.965117 2016] [mpm_winnt:notice] [pid 5284:tid 488] AH00354: Child: Starting 64 worker threads. [Tue Nov 01 15:43:45.824744 2016] [mpm_winnt:notice] [pid 11416:tid 488] AH00364: Child: All worker threads have exited. [Tue Nov 01 15:43:57.216633 2016] [:error] [pid 5284:tid 1072] [client ::1:61697] PHP Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\\WebServer\\Apache24\\htdocs\\html\\www\\mail.php on line 11 [Tue Nov 01 15:44:17.866775 2016] [mpm_winnt:notice] [pid 1564:tid 556] AH00424: Parent: Received restart signal -- Restarting the server. AH00112: Warning: DocumentRoot [C:/Apache24/htdocs] does not exist AH00526: Syntax error on line 144 of C:/WebServer/Apache24/conf/extra/httpd-ssl.conf: SSLCertificateFile: file 'C:/Apache24/conf/server.crt' does not exist or is empty [Tue Nov 01 15:44:19.869320 2016] [mpm_winnt:notice] [pid 5284:tid 488] AH00364: Child: All worker threads have exited. Para além de não saber qual o ficheiro onde está o tal documentroot (o meu é C:\WebServer\Apache24\htdocs\html\www) reparei que o tal ficheiro como não encontro esse tal server.crt fui procurar como o encontrar, parece que vai ser mais complicado que parecia... :S (O DocumentRoot já foi alterado, como o apache não reinicia devido a erro ainda aparece o link errado) Lembrei-me de correr o OpenSSL que descarreguei daqui http://slproweb.com/products/Win32OpenSSL.html na linha de comandos mas como Admin. Criou o certificado de acordo com os dados que dei. Obviamento tudo inventado xD Depois do certificado criado foi só colocar em C:\WebServer\Apache24\conf. Reiniciei o apache e desta vez sem problemas. Tudo ok. Quando fui novamente correr o mail.php através do localhost continua a dar este erro Warning: mail(): Failed to connect to mailserver at "tls://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\WebServer\Apache24\htdocs\html\www\mail.php on line 10 Edited November 1, 2016 at 04:34 PM by sEnte "If It Ain't Broke, Break it and build something Cooler!" Unknown
jdanielmedina Posted November 5, 2016 at 06:10 AM Report #600159 Posted November 5, 2016 at 06:10 AM Estás a usar um servidor local? Eu tive problemas em usar o serviço de e-mail (do PHP) no meu aljamento mas recorri às configs do SMTP... Sugiro que não uses a função 'mail'. vê isto...http://github.com/eoghanobrien/php-simple-mail
sEnte Posted November 6, 2016 at 06:12 PM Author Report #600195 Posted November 6, 2016 at 06:12 PM Quando descobri o problema até estava a usar PHPMailer. Como quando deveria receber o mail e ele não aparecia, lembrei-me de usar a função mais básica para ver onde estava o problema, se era eu que estava a configurar mal a minha app ou se era problema de configs gerais, do tipo o PHP estar a bloquear alguma coisa. Só por esse motivo é que recorri à função mail(); No entanto parece-me que é alguma config de PHP que não envia o mail. "If It Ain't Broke, Break it and build something Cooler!" Unknown
Rui Carlos Posted November 6, 2016 at 07:00 PM Report #600200 Posted November 6, 2016 at 07:00 PM Já adicionaste os dados de autenticação do Gmail? Verificaste também se a conta Gmail que estás a usar permite SMTP? (Podes tentar configurar um cliente como o Outlook ou o Thunderbird para testar.) Já agora, uma das vantagens de usares o PHPMailer é que não precisas de mexer nas configurações SMTP do PHP, pois o PHPMailer permite-te definir os dados de conexão e autenticação directamente pela API. Rui Carlos Gonçalves
sEnte Posted November 7, 2016 at 09:51 PM Author Report #600237 Posted November 7, 2016 at 09:51 PM Ou não estou a ver o erro, ou estou a fazer alguma coisa mal e não sei... 7QszWGb.png no php.ini tenho tudo o que estava por definição, depois de reiniciar o apache corri o script e mesmo assim nada!!!! "If It Ain't Broke, Break it and build something Cooler!" Unknown
sEnte Posted November 11, 2016 at 11:58 PM Author Report #600329 Posted November 11, 2016 at 11:58 PM Mudei do PHPMailer para o Mailgun e aparece-me isto. cURL error 60: SSL certificate problem: unable to get local issuer certificate Parece que basta tratar do SSL mas não estou a conseguir. Podem ajudar? "If It Ain't Broke, Break it and build something Cooler!" Unknown
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now