简体   繁体   English

@ .SYNTAX-ERROR。 在PHP邮件发件人中

[英]@.SYNTAX-ERROR. in PHP mail sender

I am using a HTML form to forward inputs via ajax to a PHP file, where an e-mail is sent using PHPMailer. 我正在使用HTML表单通过ajax将输入转发到PHP文件,在该文件中使用PHPMailer发送电子邮件。 I use JQuery to validate some inputs (name and mail address) before the data is sent to the PHP file. 在将数据发送到PHP文件之前,我使用JQuery验证了一些输入(名称和邮件地址)。

Here is my code: 这是我的代码:

HTML Form: HTML表单:

<form class="ajax" action="script/send_form.php" method="post">
        <input id="name" name="name" type="text"  />
        <input id="mail" name="mail" type="text"  />
        <input id="mail" name="note" type="text"  />
        <button type="submit" id="send">Send</button>
</form>

The PHP file using the Autoload function of PHPMailer: 使用PHPMailer的自动加载功能的PHP文件:

    <?

$return = chr(13).chr(10);
$line = "-----------------------------------------------".$return;

$name = '';
$email = '';

if(!empty($_POST['name'])) {
    $name = $_POST['name'];
}

$email = $_POST['mail'];
$note = $_POST['note'];

$msg = $note;

require 'phpmailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';

//Set who the message is to be sent from
$mail->From = $email;
$mail->FromName = $name;


//Set who the message is to be sent to
$mail->addAddress('info@internet.com', 'John Doe');

//Set the subject line
$mail->Subject = 'Some Subject';


$mail->Body = $msg;

//send the message, check for errors
if (!$mail->send()) {
    echo "Mail Error: " . $mail->ErrorInfo;
} else {
    echo "Sent";
}

?>

Jquery: jQuery的:

   function validateEmail(email) { 

    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

function validate(){
    var email = $("#mail").val();
      if (validateEmail(email)) {
          var mail = $('#mail').val();
      } else {
  alert ('Bitte gültite E-Mail Adresse eingeben!') 
      }
}

function dottedButton () {
  document.getElementById('send').innerHTML = '...';
} 


$('form.ajax').on('submit', function(ev){
     ev.preventDefault();
     validate ();

     var name = $('#name').val();
     var mail = $('#mail').val();

     if(name && mail){

            var that = $(this);
                url = that.attr('action');
                type = that.attr('method');
                contents = that.serialize();
        dottedButton ();

            $.ajax({
                url: url,
                type: type,
                data: contents,
                success: function(response){
                    document.getElementById('send').innerHTML = 'sent';
                }
            });
     } else {
        alert ('pleas fill out all fields!') 
     };
    return false;
});

The problem is: in unregular intervals (every one or two days) i have an e-mail in my inbox, that is empty and the sender e-mail address says: @.SYNTAX-ERROR. 问题是:在不定期的间隔中(每隔一两天),我的收件箱中有一封电子邮件为空,发件人的电子邮件地址说:@ .SYNTAX-ERROR。

I have no clue, why this is happening. 我不知道为什么会这样。 Might it be possible that some bot autosends the PHPMailer? 某些机器人可能会自动发送PHPMailer吗?

BTW: My hoster is hoststar.at 顺便说一句:我的房东是hoststar.at

Thanks in advance! 提前致谢!

Don't do this: 不要这样做:

$mail->From = $email;
$mail->FromName = $name;

You're trying to forge the sender address and you will have delivery trouble, and you're open to problems like you're seeing. 您正在尝试伪造发件人地址,并且会遇到发送问题,并且容易遇到类似问题。 Just put the submitted from address in the message body, or reply-to if you need it in headers. 只需将提交的发件人地址放入邮件正文中即可;如果需要,则将其回复到标题中。

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

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