doudun2565 2018-10-16 06:11
浏览 110

表单提交 - 从字段制作访客电子邮件

I created a form submission that works. I get an email from ipg.blahblah@blahblah.com when someone fills out the form and submits it to me. Is there a way to change the From field in the email to be the visitor's email?

An example, Henry fills out my form and writes his email as henry@gmail.com and submits it to me. I'll get an email from ipg.blahblah@blahblah.com, is there a way to change ipg.blahblah@blahblah.com to henry@gmail.com?

I want to make it easier for me to just reply back to the email instead of creating a new email and replying back to Henry. I'm not sure if I can change it in my mail handler. Any pointers? I'll attach my mail handler code below.

<?php
if(isset($_POST['submit'])){

    $url = 'Hidden';
    $privatekey = "Hidden";

    $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);

    $data = json_decode($response);

    if(isset($data->success) AND $data->success==true){

        //mail handler code 
                if(isset($_POST['submit'])){
                $name=$_POST['name'];
                $email=$_POST['email'];
                $phone=$_POST['phone'];
                $msg=$_POST['msg'];
                $port = '25';

                $to='Hidden';
                $message="Form Submission: ".$name;
                $headers="Name: ".$name."
"."From: ".$email. "
". "Phone:".$phone."
". "Wrote the following: "."

".$msg;


                if(mail($to, $message, $headers)){

                    header('Hidden');
                }
            }


    }else{


        header('Hidden');


    }


}



?>
  • 写回答

1条回答 默认 最新

  • douweng7308 2018-10-16 07:11
    关注

    What Magnus said. Look at the contact form example provided with PHPMailer for the right way to do it. Many email providers (for example gmail) will not let you set the from address at all, and doing so will lead to SPF failures as it’s forgery. Use your own address as the from address, and put the submitters address in a reply-to.

    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊