开发者

php mail breaks when trying to send the word "localhost" in email body - so weird

开发者 https://www.devze.com 2023-03-13 15:35 出处:网络
I\'ve got a php mail form that buyers fill out to send an email to a seller. Everything works fine, except that I\'m testing it on my localhost MAMP server.

I've got a php mail form that buyers fill out to send an email to a seller. Everything works fine, except that I'm testing it on my localhost MAMP server.

Problem: $message1 (the email body) comes from a $_POST['textarea']. If there is the url "http://localhost" sent through the form text area (placed in the email body), then the dang email never gets delivered. http://www.anythingelse.com works fine....I'm quite perplexed. Is there some safety feature that disables localhost urls being sent through a form?

If there are any other glaring errors in my code, any help is appreciated.

Regards, Daniel

public function saleRequest($seller_email, $seller_username, $buyer_email, $buyer_username, $book_title, $subject1, $message1) {


    define("NAME","xxxxxxx");
    define("FROM",$buyer_email);

    $subject = substr_replace($subject1, '', 30);

    // -=-=-=-=- MAIL HEADERS

    $mime_boundary = md5(time()); 
    $headers = "From: ".NAME." <".FROM.">\n";
    $headers .= "MIME-Version: 1.0\n"; 
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\";\n\开发者_开发知识库n"; 

    // -=-=-=-=- TEXT EMAIL PART

    $message = "--$mime_boundary\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\n"; 
    $message .= "Content-Transfer-Encoding: 8bit\n\n"; 

    $message .= wordwrap(stripslashes($message1), 30, PHP_EOL)."\n";

    // -=-=-=-=- HTML EMAIL PART

    $message .= "--$mime_boundary\n"; 
    $message .= "Content-Type: text/html; charset=UTF-8\n"; 
    $message .= "Content-Transfer-Encoding: 8bit\n\n"; 

    $message1 = $message1."this is html";

    $message .= nl2br(wordwrap(stripslashes($message1), 30, "<br>"))."<br>\n";

    // -=-=-=-=- FINAL BOUNDARY

    $message .= "--$mime_boundary--\n\n";
    unset($mime_boundary);
    return mail($seller_email,$subject,$message,$headers);
}


Sounds like a spam filter. It makes sense for most SMTP servers to filter out mail containing localhost URLs.

Check the headers of one of the working messages. Look which servers it have passed through (Received lines) and ask the sysadmins of those servers, or even better: configure your mail server to deliver all test mails locally and don't send them through any third party. That way you have control over the environment. If you already have control over all the mail servers involved, check their log files.


Is there some safety feature that disables localhost urls being sent through a form?

No. At least not within PHP. Might be a mailserver issue, but that's to check with every MTA.

0

精彩评论

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

关注公众号