简体   繁体   中英

sending mail working locally but not in server

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:


: Function name must be a string in on line :函数名称必须是第行的的字符串
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*

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

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

Try replacing

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

for

if(!$padrao){die("Erro ao ligar a ".$servidor);}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM