1

I've already searched, and none of the questions here helped me to solve my problem.

I have to send an email on the website that I'm working on, it works locally, but when I try sending one on the server, it gives me a fatal error.

the code:

send_mail.js

$(function() {
   $('.enviar').click(function(){
      event.preventDefault();
      $.ajax({
      url: 'modules/send_mail.php',
      type: 'POST',
      data : {
        nome : $('#nome').val(),
        mail : $('#mail').val(),
        assunto : $('#assunto').val(),
        mensagem : $('#mensagem').val()
      },
      success: function (data) {
         console.log(data);
      },
      error: function(xhr, textStatus, data) {
        console.log(xhr.statusText);
        console.log(textStatus);
        console.log(data);
      }
    });
   });
});

send_mail.php

<?
include_once ('../config.php');

$mail_to = "ricardo.ac.dc@gmail.com";
$nome = stripslashes(strip_tags($_POST['nome']));
$mail = stripslashes(strip_tags($_POST['mail']));
$assunto = stripslashes(strip_tags($_POST['assunto']));
$mensagem = stripslashes(strip_tags($_POST['mensagem']));

$texto = $nome ."(". $mail . ")\r\n";
$texto .= $mensagem;

mail ($mail_to,$assunto,$texto);    
?>

form.php

<div class="form_contactos">
   <div class="form_text">
      <input name="nome" id="nome" placeholder=" nome" type="text" class="linha_simples"/>
      <input name="mail" id="mail" placeholder=" e-mail" type="email" class="linha_simples"/>
      <input name="assunto" id="assunto" placeholder=" assunto" type="text" class="linha_simples"/>
   </div>

   <textarea name="mensagem" id="mensagem" placeholder=" mensagem"  class="caixa_texto"></textarea>
   <input type="submit" name="enviar" class="submit_button enviar" id="enviar" value="" />

</div>

config.php

<?php

$ligacao = 'local';

if ($ligacao == 'server')
{
    //Para ligar a SQL Server, utilizar PHP 5.2.6 (Wampserver 2C)
    $servidor = "localhost";
    $utilizador = "s002349_admin";
    $password = "Torre2008";
    $bd = "s002349_temp_almadados";

}
else
{

    //Para ligar a SQL Server, utilizar PHP 5.2.6 (Wampserver 2C)
    $servidor = "localhost";
    $utilizador = "root";
    $password = "root";
    $bd = "almadados";
}


//Ligação à BD
$padrao = mysql_connect($servidor, $utilizador, $password)
or die("Erro ao ligar a $servidor");

//Selecção de BD a utilizar
$seleccao = mysql_select_db($bd, $padrao)
or die("Erro ao aceder a $bd");

?>

The error that I receive is this one:


Fatal error: Function name must be a string in /home/s002349/public_html/almadados.net/new_site/modules/send_mail.php on line 26
send_mail.js:22

Can anyone help me with this problem?

I thought of something that could work... I'm going to have to implement phplist on this site, so my idea was to send this mail also by the phplist, could this work, and solve my problem?

*I've cleared all the blank lines on the send_mail.php and cleared all the cache on the browser, so I don't understand why it still shows that line*

4

3 回答 3

0

First thing change this <? to this <?php, some server cannot support short tags

After if npt work, try to change this:

mail ($mail_to,$assunto,$texto); 

to this:

mail($mail_to,$assunto,$texto); 

There is a blank space between the function name and brackets

UPDATE
change this:

$padrao = mysql_connect($servidor, $utilizador, $password)
or die("Erro ao ligar a $servidor");

to this:

$padrao = mysql_connect($servidor, $utilizador, $password)
if (!$padrao)
  {
  die('Could not connect: ' . mysql_error());
  }

same thing for the variable $seleccao

于 2013-08-22T16:42:21.817 回答
0

This could be because the server doesn't support short tags. I highly suggest staying away from these. Replace <? with <?php

于 2013-08-22T16:42:23.383 回答
0

Try replacing

or die("Erro ao ligar a $servidor");

for

if(!$padrao){die("Erro ao ligar a ".$servidor);}
于 2013-08-22T17:32:51.537 回答