简体   繁体   English

邮件功能的主题问题-PHP

[英]Subject issue with mail function - PHP

I'm trying to send e-mail using PHP. 我正在尝试使用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 在index.php中

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

In functions.php 在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. 因此,如果您没有启用所有常见的SPAM预防机制,就无法从计算机或服务器发送电子邮件这么容易。

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. 因此,当您没有反向DNS条目并发送带有“测试”的电子邮件时,您不应该怀疑电子邮件是否无法发送到其他站点。 So Take a look at the SPF-System , Reverse-DNS and generic names for servers (not working for some providers). 因此,请看一下服务器的SPF-System反向DNS和通用名称(不适用于某些提供程序)。 Then you can send some E-Mails. 然后,您可以发送一些电子邮件。

To find some problems check your mail log /var/log/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. 当您尝试防止该问题时,请使用提供商提供的SMTP帐户,然后通过SMTP发送该电子邮件。

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

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