简体   繁体   中英

Subject issue with mail function - PHP

I'm trying to send e-mail using PHP. I took a piece of code that I have been using earlier, but it doesn't work anymore. I figure out the problem was coming from the subject.

When my subject is "test", the mail is sent, but when my subject is anything else with for example capital letters, like "Test", it doesn't work. I'm pretty sure this is a quick fix, but I can't find the answer.

Here is my code.

In index.php

    $subject= 'test';
    $message = implode("\n" , $_SESSION['data']);
    mail_html($subject, $message, $email);

In functions.php

function mail_html ( string $subject, string $message, string $receiver) {
    $headers = 'From: Template <me@me.com>' . "\r\n";
    $headers  .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8';

    mail($receiver, $subject, $message, $headers);

}

Thank you everyone for helping me. I feel stupid getting blocked by things like that.

Sending E-Mails is a very difficult process. So you can't send E-Mails so easy from your Computer or Server if you don't have alle the common SPAM prevention mechanisms enabled.

So when you don't a Reverse-DNS entry and you send an Email with "Test" you should not wonder if the emails can't send to the other site. So Take a look at the SPF-System , Reverse-DNS and generic names for servers (not working for some providers). Then you can send some E-Mails.

To find some problems check your mail log /var/log/mail.log .

When you try to prevent that problems use an SMTP account from your provider and send that E-Mails over SMTP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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