PHP电子邮件提交表单接收者未收到正确的发送者电子邮件地址 [英] PHP email submit form receiver not receiving the correct sendr email address

查看:83
本文介绍了PHP电子邮件提交表单接收者未收到正确的发送者电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出用于提交表单的PHP代码的问题,我正在为我的朋友做。它通过发送电子邮件,但是问题是收件人收到的电子邮件地址很奇怪。我正在附上图片,以进行更仔细的查看。

Im trying to figure out the problem with the PHP code for submit form, im doing for my friend. It is sending the emails through, but the problem is that the receiver gets a very odd email address. I am attaching an image to have a closer look.

我的PHP代码是:

<?php 
    $error = false;
    $sent = false;

    if(isset($_Post['name'])) {
        if(empty($_Post['name']) || empty($_Post['email']) ||  empty($_Post['comments'])) {
            $error = true;
        } else {

        $to = "linardsberzins@gmail.com";

        $name = trim($_Post['name']);
        $email = trim($_Post['email']);
        $comments = trim($_Post['comments']);

        $subject = "Contact Form";

        $messages =  "Name: $name \r\n Email: $email \r\n Comments: $comments";

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From:" . $name . "\r\n";
        $mailsent = mail($to, $subject, $messages, $headers);

        if($mailsent) {
            $sent = true;
        }
    }
}
?>

非常感谢

推荐答案

发件人应该是这样的发件人< HIS @ EXAMPLE.COM>

 $headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";

这篇关于PHP电子邮件提交表单接收者未收到正确的发送者电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆