开发者

small problem using PHP mail function with jQuery

I'm getting the following error when submitting an email contact form using PHP mail function and jQuery:

SMTP server response: 554 The message was rejected because it contains prohibited virus or spam content in mail.php on line 26

Here is the code I'm using for the PHP:

   $mailTo = "info@***.com";
   $mailFrom = $_POST['email'];
   $subject = "RFP Inquiry";
   $message = $_POST['message'];


   mail($mailTo, $subject, $message, "From: ".$mailFrom);

Here is the code I'm using for the jQuery AJAX call:

    //var name = $("#contactname").val();
var email = $("#email").val();
var message = $("#subject").val();
//var age = $("#message").val();
   var datastr ='email=' + email + 'message=' + message;


  $('#submit').click(function(){

$.ajax({
type: "POST",
url: "mail.php",
data: datastr,
cache: false,
 error: function () {

    alert('did not go thru');
   },
success: function(html){
//$("#response").fadeIn("slow");
$("#tab1").html(html);
//setTimeout('$("#response").fadeOut("slow")',2000);
alert('mail sen开发者_如何转开发t');
}
});


 });


I prefer to use:

data: ({email : $("#email").val(), message: $("#message").val()}),

Maybe the problem occurs in your mail function. It would be more clear if you post your mail function's code.


here is the entire mail function code. the first section is commented out b/c i thought something was wrong with it.

    <?php
/*
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];

    $email_from = "info@***.com";
    $email_from2 = $visitor_email;
    $email_subject = "Inquiry";
    $email_body = "here is the body of the message".


    $to = "info@***.com";
    $headers = "From: $email_from";
    //$headers .= "Reply-To: $visitor_email";
    //Send email!
    mail($to,$email_subject,$email_body,$headers);
*/

$mailTo = "info@***.com";
$mailFrom = $_POST['email'];
$subject = "Inquiry";
$message = $_POST['message'];


mail($mailTo, $subject, $message, "From: ".$mailFrom);
?>


You're missing an ampersand in your datastr:

var datastr ='email=' + email + 'message=' + message;

should be

var datastr ='email=' + email + '&message=' + message;

UPDATE

The SMTP error is coming from the SMTP server, so you should speak to whoever runs that and find out what criteria they have set in order to detect Spam.

My guess is that an email with no body constitutes Spam by their definition. The error with datastr above would result in a NULL body. Also, if you're doing testing without putting any prose in the message text box, that would also result in a zero-length body.

Note... I'm speculating as to why your messages are being considered Spam... talk to the SMTP server owner to find out more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜