1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP "Invalid Date: header (not RFC 2822)"

Discussion in 'PHP' started by postcd, Apr 30, 2022.

  1. #1
    SpamAssasin complains that the date format is wrong.
    0.4 INVALID_DATE Invalid Date: header (not RFC 2822)
    SEMrush
    Supplied date is:
    Date: Sat, 30 Apr 2022 11:20:15 0200

    as a result of mail PHP script code:
    $this->_add_hdr('Date', sprintf(date(DateTime::RFC2822)));
    or
    $this->_add_hdr('Date', sprintf(date("D, d M Y H:i:s O")));

    (it seems to display same format no matter which line i use)
    Do you have an idea how that PHP code line should look like so the error does not appear?
     
    postcd, Apr 30, 2022 IP
    SEMrush
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,615
    Likes Received:
    1,964
    Best Answers:
    248
    Trophy Points:
    515
    #2
    Why are you using sprintf with only one property? That's the first thing I'd axe.

    Why are you using DateTime's property which is for the DateTime object, and not DATE_RFC2822 which is for the date() function?

    What does _add_hdr look like for your object. Are you sure it even accepts a string of this type? Most of the time in mail headers the date is set automatically when you use something like sendmail.

    Guessing WILDLY I'd think what you're trying to do is:

    $this->_add_hdr('Date', date(DATE_RFC2822));
    Code (markup):
    But I'd have to know a hell of a lot more about the object you have as $this as that's highly non-standard and seemingly wasteful if all your doing is sending an email. Especially now that mail() accepts headers as an associative array.

    But then I've been increasingly unimpressed with the batshit crazy hoops people retain from PHP 5.1 / earlier practices now that we're all the way up to PHP 8.1 -- particularly dumbass frameworks and pointless wrapping objects/singletons for things that are now NATIVE and thus easier in the vanilla language.

    Dimes to dollars whatever the object is that you're using to put together your e-mails is as at fault as the nonsensical sprintf(date(wrongObject:: property)) you've got there.

    Might even be your best option is to stop trying to set the date since any DECENT mailer should be handling that for you, even PHP's simple mail() function!
     
    Last edited: May 2, 2022
    deathshadow, May 2, 2022 IP
  3. postcd

    postcd Well-Known Member

    Messages:
    1,027
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #3
    Because i know nearly nothing about a PHP not being developer I have just reused the line that was already in the PHP file and that was doing similar task i wanted to do.

    This is the whole file includes/smtp/smtp.lib.php . Around the line 120 you can see various values i have tried. Yours is missing, but i have tried it too without success.

    Do you please have idea how that line should look like differently so it works? Thank you
     
    postcd, May 3, 2022 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,615
    Likes Received:
    1,964
    Best Answers:
    248
    Trophy Points:
    515
    #4
    There are two major issues with that code.

    1) It's kind of a kludgy outdated mess trying to manually do e-mail manually in a manner that ... I'm not even sure is supported anymore. That it sends at all surprises me.

    2) Did I mention how outdated it is? It has a lot of telltales of being PHP 4 that's not been updated to WORKING practices in nearly 20 years. I'd be shocked if it even runs on PHP 5.x much less modern PHP 8. The presence of "var" for example -- something most PHP dev's today don't even know is part of PHP -- was replaced by "public' in PHP 5.0, though it was put back in when some people complained its removal broke existing code. Like most web development, the creators of these languages are too spineless to make proper changes.

    There are even telltales that the original author didn't know enough about programming to write a system like that.

    
    		if ((int)$resp{0} != 2) {
    			return false;
    		} else {
    			return true;
    		}
    
    Code (markup):
    For example, showing they don't understand IF, comparisons, literal results... That's a warning sign that if the rest of the system works that way, it's time to deep six it and start over.

    What it does is an attempt to send e-mails from servers not configured to send e-mails... in which case my advice would be to throw most all of that in the trash and start over, and if you "need" that sort of code on the back end just to send e-mails, get better hosting!

    Why? Because on decent hosting that has sendmail or an equivalent on it, 95% of that code would be replaced by calling PHP's mail() function. That's 10k of code doing less than half a k's job.

    The trick being finding where SMTP is being called and replacing that with less kludge and more sanity.
     
    deathshadow, May 4, 2022 IP
  5. postcd

    postcd Well-Known Member

    Messages:
    1,027
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #5
    Interesting, thank You. Though as mentioned, I am not a developer (+was unable to find one) so any yours mentioned changes is beyond what i can do.
    I wanted to know what to replace by what in existing code provided here. If not possible to display the date correctly (as mentioned in the initial post) then i will leave it like it is.
    I had some problems with php mail() function sending (the CMS has that option beside SMTP). Some provider require SMTP sending as a SPAM protection and maybe less likely to be marked as SPAM. Just tested PHP mail() option, not delivered mail, so that is why i am using SMTP and if can not fix the date format as described, i guess will leave it like it is.
     
    postcd, May 5, 2022 IP
  6. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,203
    Likes Received:
    818
    Best Answers:
    7
    Trophy Points:
    320
    #6
    Guess that means you need to bite the bullet and learn like so many others have been forced to do.
     
    mmerlinn, May 5, 2022 IP
  7. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #7
    So anything short of writing the correct code for you would not suffice since you have stated you aren't a developer and have no idea how to follow any technical written recommendation to fix the code....so what do you want or expect? You specifically asked for the answers you received. Now you need someone to just do it for you? It's OK to ask...I just don't find you seeing any success with that. It's an utter waste of time to even reply with giving you guidance or advice since you stated you have no idea about programming at all. You need to hire someone or start learning.
     
    NetStar, May 27, 2022 IP
  8. postcd

    postcd Well-Known Member

    Messages:
    1,027
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #8
    I can follow recommendation like: replace line ABC by line EFG. So if any knows, let me know. For discussion about my abilities etc. please send me a PM to keep this on topic.
     
    postcd, May 31, 2022 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,615
    Likes Received:
    1,964
    Best Answers:
    248
    Trophy Points:
    515
    #9
    Unfortunately with code 20+ years out of date, that might not even run on modern hosting, riddled with bad practices even in its time period...

    It's not as simple as replacing A with B. That's trying to fix a .500 Winchester magnum bullet hole with a band-aid.

    I'd have to see a hell of a lot more of the code to even properly weigh in, and even then I'd suggest that whatever this is needs to be put down like Old Yeller and rewritten from scratch.
     
    deathshadow, Jun 19, 2022 IP
    postcd likes this.