简体   繁体   English

发送本地工作但不在服务器中的邮件

[英]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 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 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 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 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 致命错误 :函数名称必须是第26行的/home/s002349/public_html/almadados.net/new_site/modules/send_mail.php中的字符串
send_mail.js:22 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? 我想到了一些可行的方法...我将不得不在该站点上实现phplist ,所以我的想法是也要通过phplist发送此邮件,这样可以解决我的问题吗?

*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* *我已经清除了send_mail.php上的所有空白行并清除了浏览器上的所有缓存,所以我不明白为什么它仍然显示该行*

First thing change this <? 首先改变这个<? to this <?php , some server cannot support short tags 为此<?php ,某些服务器不支持短标签

After if npt work, try to change this: 如果npt有效,请尝试更改以下内容:

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 $seleccao变量$seleccao

This could be because the server doesn't support short tags. 这可能是因为服务器不支持短标签。 I highly suggest staying away from these. 我强烈建议您远离这些。 Replace <? 替换<? with <?php <?php

Try replacing 尝试更换

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

for 对于

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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