首页 > 解决方案 > PHP xammp sendmail 错误:邮件缺少发件人地址

问题描述

我已经在我的家用电脑上运行的 localhost xammp 服务器上设置了 Sendmail 客户端,但我收到以下错误:xx-xx-xx xx:xx:xx: Message is missing sender's address. 当我使用我想要发送的硬代码时,我已经让它工作了,就像这样:

$msg = "hello world";

mail("example@gmail.com","My subject",$msg, 'From: admin@myEmailClient.com');

但是当我尝试实现我的登录验证脚本时它不起作用并且我得到了上述错误。

emailvalidation.php

        $to = $email;
        $sub = 'email verification';
        $msg = "<a href='http://localhost/verify.php?vkey=$vkey'>account verification </a>";
        $headers = "From: admin@myEmailClient.com \r\n";
        $headers = "MIME-Version: 1.0". '\r\n';
        $headers = "Content-type:text/html;charset=UTF-8 ". '\r\n';


        mail($to, $sub, $msg, $headers);

如果有帮助,我email的变量是由用户设置的,我认为解析的项目没有问题,因为当我检查数据库时,所有行都已正确填写。

感谢您的时间

编辑

我认为这是 r\n 部分的问题,这些部分是在电子邮件中启用 HTML 的部分。当我摆脱它们时,它会起作用

标签: phpemailxamppsendmail

解决方案


I'm not sure if I should delete this question because of the speed I was able to solve it but I hope this helps someone who had the same problem as I did.

here is how I solved the problem

        $message = "<a href='http://localhost/verify.php?vkey=$vkey'>account verification </a>";

        $to = $email;
        $subject = 'account validation';
        $from = 'admin@myEmailClient.com';
 
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
        $headers .= 'From: '.$from."\r\n".
        'Reply-To: '.$from."\r\n" .
        'X-Mailer: PHP/' . phpversion();

        if(mail($to, $subject, $message, $headers)){
            echo 'Your mail has been sent successfully.';
        } else{
            header("location: index.PHP");
        }

I got the solution from here. tutorial republic


推荐阅读