我在html中有一个联系表格的代码:
<form method=post action=sendmail.php>
<div class=one_third>
<label>Name</label>
<input type=text name=author value id=name />
</div>
<div class=one_third>
<label>Email</label>
<input type=text name=email value id=email />
</div>
<div class="one_third last">
<label>Subject</label>
<input type=text name=subject value id=subject />
</div>
<div class=full_width>
<label>Your Message</label>
<textarea name=msg id=msg></textarea>
</div>
<input type=submit name=submit value=Submit />
</form>
我想知道你是否可以提供我的PHP代码,进入实际发送电子邮件的“sendmail.php”。
答案 0 :(得分:1)
首先,您应该在发布问题之前尝试寻找答案,这几乎是谷歌搜索“php发送邮件”的第一个结果将显示:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$from = $_REQUEST['author'] ;
$to = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['msg'] ;
mail($to, $subject, $message, "From:" . $from);
// the mail was sent
echo "Thank you for using our mail form";
}
else {
//if "email" is not filled out, display the form
//just close php and copy the code for your form
?>
- paste your html form here -
<?php
}
?>
第二件事是,我不知道您想对作家字段做什么。我怀疑你从来没有发过电子邮件,你必须输入你在任何输入字段中的身份。客户端类型为您做到了这一点。因此,考虑到这一点,我只是在邮件的底部留下作者。
这一切都为您提供了在php.ini配置设置中设置的可用电子邮件系统。
答案 1 :(得分:0)
如果您有任何疑问,请告知我们,您可以使用上面发布的表单。
<?php
/* Subject and email variables */
$emailsSubject = 'This is where you type what you subject will show up as';
$webMaster = 'youremail@gmail.com';
/* Gathering Data Variables - Whats in the form */
$name = $_POST ['name'];
$email = $_POST ['email'];
$subject = $_POST ['subject'];
$msg = $_POST['msg'];
/*Security*/
/* What You Want To See In The Email Place Inbetween $body = <<<EOD and EOD; */
$body = <<<EOD
<strong>Client:</strong> $name
<br />
<br />
<strong>Email:</strong> $email
<br />
<br />
<strong>Subject:</strong> $subject
<br />
<br />
______________________________________________
<br />
<br />
$msg
EOD;
/* Headers is a tag containing the users email and how you want it to display in your email */
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
/* This is what sends the email */
$success = mail($webMaster, $emailsSubject, $body, $headers);
/* Results Rendered as Html */
echo file_get_contents("http://yourdomain.com/after-message-sent/");
?>
对于“echo file_get_contents”,您可以创建一个页面,希望客户端看到该页面后告诉他们已发送消息。如果你想要简单的Jane那么只需回显你的消息已发送。希望这可以帮助。