Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过收集用户通过表单提供的信息向所有者发送电子邮件?_Php_Email_Phpmailer - Fatal编程技术网

Php 通过收集用户通过表单提供的信息向所有者发送电子邮件?

Php 通过收集用户通过表单提供的信息向所有者发送电子邮件?,php,email,phpmailer,Php,Email,Phpmailer,我设计了一个用户输入表单,收集用户名、电子邮件地址、主题和消息。 我已经验证了所有存储在变量中的元素。 现在我需要通过电子邮件将此信息发送给所有者。 如何在localhost(太)中解决此问题 如何向所有者发送电子邮件 如何添加所有信息,以便稍后在所有者电子邮件中获得或更改 contact.php 名字* 电子邮件地址* 主题 信息* 联系_ok.php 关于发送邮件,我读了关于PHP mailer的文章,但我发现很难理解。而且我学的还不够。 2.为了存储所有元素,我尝试

我设计了一个用户输入表单,收集用户名、电子邮件地址、主题和消息。 我已经验证了所有存储在变量中的元素。 现在我需要通过电子邮件将此信息发送给所有者。 如何在localhost(太)中解决此问题

  • 如何向所有者发送电子邮件
  • 如何添加所有信息,以便稍后在所有者电子邮件中获得或更改
  • contact.php

    
    
    名字*
    

    电子邮件地址*

    主题

    信息*

    联系_ok.php

    
    
    关于发送邮件,我读了关于PHP mailer的文章,但我发现很难理解。而且我学的还不够。 2.为了存储所有元素,我尝试使用
    $msg=str\u split($msg)

    使用
    push_array($msg)
    推送所有其他信息,并使用
    print_r($msg,TRUE)
    进行更改,但它不起作用。

    首先,我们让mailto功能起作用。(使用本地主机和电子邮件程序,如Thunderbird或Outlook或Mail)
    此后,您可以使用Swiftmailer。(比PHPmailer更容易) 我添加了一些javascript验证 另外,最好使用文本区域而不是文本框,因为它们保留空白。 稍后,当您添加数据库代码时,可以使用TEXT而不是VARCHAR。 (我遗漏了一些你需要填写的内容)享受吧

    contact.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <title>Registration</title>  
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />  
    <script type="text/javascript">  
    
    function formValidator(){  
    var subject = document.getElementById('subject');  
    var usermail = document.getElementById('useremail');  
            if(notEmpty(subject, "Please enter an email subject")){  
            if(emailValidator(usermail, "Please enter email addr")){  
                            return true;  
        }  
    }  
    return false;
    
    }//very important end of formvalidator!!
    
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    </script>
    </head>
    <body>
    <form onsubmit="return formValidator()" action="contact_ok.php" method="post">
    
    <textarea id='username' name='username'  style='white-space:pre-wrap; height:18px;font-family:arial;width:200px;font-size: 10pt'  >
    </textarea>  
    </body>  
    </html>  
    
    
    登记
    函数formValidator(){
    var subject=document.getElementById('subject');
    var usermail=document.getElementById('useremail');
    如果(notEmpty(主题,“请输入电子邮件主题”){
    如果(emailValidator(usermail,“请输入电子邮件地址”){
    返回true;
    }  
    }  
    返回false;
    }//非常重要的formvalidator结尾!!
    函数notEmpty(elem,helperMsg){
    if(elem.value.length==0){
    警报(helperMsg);
    elem.focus();//将焦点设置为此输入
    返回false;
    }
    返回true;
    }
    功能emailValidator(elem、helperMsg){
    var emailExp=/^[\w\-\.\+]+\@[a-zA-Z0-9\.-]+\.[a-zA-Z0-9]{2,4}$/;
    if(元素值匹配(emailExp)){
    返回true;
    }否则{
    警报(helperMsg);
    元素焦点();
    返回false;
    }
    }
    
    联系_ok.php

    <?php
    $username = "_";
    $usermail = "_";
    $subject  = "_";
    $msg = = "_";
    $from ='owner@gmail.com';
    
    $username = ($_POST['username']);
    $usermail = ($_POST['usermail']);
    $subject = ($_POST['subject']);
    $msg =($_POST['msg']);
    
    $aa = "Hi";
    $a0 = "Welcome.";
    $nl = "%0D%0A"; //new line
    echo "<br><br>";
    ?>
    
    <font size = 4><b>
    <a href="mailto:<?php echo $useremail?>?subject=<?php echo $subject; ?>&body=<?php echo $aa.$nl.$a0.$nl ?>">
    Click to EMail  customer</a><br>
    </font>
    <br>
    
    
    


    如果您想使用gmail地址发送自动邮件,我建议您使用以下链接: 和
    有不同的方法:

    1) 您可以使用库发送电子邮件。所以这个库完全基于SMTP。您必须指定第三方SMTP服务和凭据。你可以通过gmail、yahoo等发送电子邮件。通过使用这个库。该库将关注安全性、标题等,并且非常易于使用

    2) 我不推荐的另一种方法是安装自己的后缀。配置所有内容并发送电子邮件。它非常耗时,您必须添加不同级别的身份验证,如SPF、DMARC等


    我建议您使用PHP Mailer集成您的SMTP服务并开始发送邮件。

    托管还是本地主机?你现在收到电子邮件了吗?@Dagon首先我想签入localhost,然后我想在线使用它!另外,我可以正确地从输入表单中获取所有信息,并希望将此信息发送给gmail帐户中的网站所有者。当前显示的消息是警告:mail()[function.mail]:无法在“localhost”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP\u port”设置或使用ini\u set()在…中,为了自动发送电子邮件,我再次提醒Swiftmailer。令人印象深刻的手册,比PHPmailer更容易理解。对于创建PDF,我推荐TCPDF。我使用了HTML5,所以我没有使用javascript表单验证技术。使用javasrcipt进行表单验证比使用HTML5更好吗//同样在contact_ok.php中,当用户从contact.php发送消息时,链接是否自动工作?我还是有点困惑!最安全的验证是PHP验证,因为如果关闭javascript,并且浏览器与HTML5不兼容,则会出现问题-但不幸的是,PHP验证只能在第二种形式(服务器端)上完成。因此建议同时使用javascript和HTML5(客户端/浏览器端)进行验证。所有浏览器都支持javascript,所以请先研究一下。HTML5对于越来越普遍的新浏览器来说是一个额外的亮点
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <title>Registration</title>  
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />  
    <script type="text/javascript">  
    
    function formValidator(){  
    var subject = document.getElementById('subject');  
    var usermail = document.getElementById('useremail');  
            if(notEmpty(subject, "Please enter an email subject")){  
            if(emailValidator(usermail, "Please enter email addr")){  
                            return true;  
        }  
    }  
    return false;
    
    }//very important end of formvalidator!!
    
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    </script>
    </head>
    <body>
    <form onsubmit="return formValidator()" action="contact_ok.php" method="post">
    
    <textarea id='username' name='username'  style='white-space:pre-wrap; height:18px;font-family:arial;width:200px;font-size: 10pt'  >
    </textarea>  
    </body>  
    </html>  
    
    <?php
    $username = "_";
    $usermail = "_";
    $subject  = "_";
    $msg = = "_";
    $from ='owner@gmail.com';
    
    $username = ($_POST['username']);
    $usermail = ($_POST['usermail']);
    $subject = ($_POST['subject']);
    $msg =($_POST['msg']);
    
    $aa = "Hi";
    $a0 = "Welcome.";
    $nl = "%0D%0A"; //new line
    echo "<br><br>";
    ?>
    
    <font size = 4><b>
    <a href="mailto:<?php echo $useremail?>?subject=<?php echo $subject; ?>&body=<?php echo $aa.$nl.$a0.$nl ?>">
    Click to EMail  customer</a><br>
    </font>
    <br>