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


send email to owner by collecting information provided by user through form?

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

  1. 如何向所有者发送电子邮件?
  2. 如何添加所有信息,以便稍后可以在所有者电子邮件中取回或更改它。

联系方式.php

<form action="contact_ok.php" method="post"  autocomplete="on">
<p>
    <label for="username"> Name <span class="required">*</span></label>
    <input type="text" name="username" required="TRUE"/>
</p>
<p> 
    <label for="usermail"> E-mail address <span class="required">*</span></label>
    <input type="email" name="usermail"required="TRUE"/>
</p>
<p>
    <label for="subject"> Subject </label>
    <input type="text" name="subject" required="TRUE" />
</p>
<p>
    <label for="message"> Message  <span class="required">*</span></label>
    <textarea name="msg" required="TRUE" ></textarea>
</p> 
<input type="submit" name="submit mail"/>   
</form>

contact_ok.php

<?php
$name = addslashes($_POST['username']);
$uml = addslashes($_POST['usermail']);
$sub = addslashes($_POST['subject']);
$msg =addslashes($_POST['msg']);
//sending mail to owner
$to ='owner@gmail.com';
//enter input information in array ******
//send email
mail($to,$sub,$msg);
?>

对于发送邮件,我阅读了有关PHP邮件的信息,但我发现很难理解。我也研究了这个线程,所以它也不够。2.为了存储所有元素,我尝试首先使用$msg=str_split($msg)将消息转换为数组并使用push_array($msg)推送所有其他信息,并使用print_r($msg,TRUE)进行更改,但不起作用。

有不同的方法:

1(您可以使用PHP MAILER库发送电子邮件。所以这个库完全基于 SMTP .您必须指定第三方 SMTP 服务和凭据。您可以通过Gmail,雅虎等发送电子邮件。通过使用此库。该库将处理证券,标题等,并且非常易于使用。

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

我想推荐你去PHP邮件集成你的SMTP服务并开始邮件。

首先,我们让 mailto 函数工作。使用本地主机和电子邮件程序,如Thunderbird或Outlook或Mail(
此后,您可以使用Swiftmailer。(比PHPmailer容易(我添加了一些JavaScript验证附言最好使用文本区域而不是文本框,因为它们保留空格。稍后添加数据库代码时,可以使用 TEXT 而不是 VARCHAR。(我省略了一些你需要填写的内容(享受!

联系方式.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>  

contact_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地址发送自动邮件,那么我推荐以下链接:https://www.google.co.za/search?q=using+swiftmailer+and+sending+with+gmail和http://www.swiftmailer.org/docs/sending.html