【发布时间】:2013-11-28 20:16:31
【问题描述】:
我设计了收集用户名、电子邮件地址、主题和消息的用户输入表单。 我已经验证了所有元素都将这些元素存储在变量中。 现在我需要通过电子邮件将此信息发送给所有者。 我怎样才能在 localhost(too) 中解决这个问题?
- 如何向所有者发送电子邮件?
- 如何添加所有信息,以便稍后在所有者电子邮件中取回或更改。
contact.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 邮件程序的信息,但我发现很难理解。我还研究了this thread on SO 这也不够。
2.为了存储所有元素,我首先尝试使用$msg=str_split($msg)将消息转换为数组
并使用push_array($msg)推送所有其他信息并使用print_r($msg,TRUE)更改它,但它不起作用。
【问题讨论】:
-
托管还是本地主机?您目前是否收到任何电子邮件?
-
@Dagon 首先我想检查本地主机然后我想在线使用它!我也可以从输入表单中正确获取所有信息,并希望将这些信息发送给他的 gmail 帐户中的网站所有者。
-
当前显示的消息是 WARNING: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, 验证 php.ini 中的 "SMTP" 和 "smtp_port" 设置或在...中使用 ini_set()