0

我在 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”,它实际上会发送电子邮件。

4

2 回答 2

1

首先,您应该在发布问题之前尝试寻找答案,这几乎是谷歌搜索“php send mail”的第一个结果将显示给您的内容:

<?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 配置设置中设置的工作电子邮件系统。

于 2013-10-20T17:05:19.183 回答
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”,您可以创建一个您希望客户看到的页面,然后告诉他们消息已发送。如果您想要简明的简,那么只需回显您的消息已发送。希望这可以帮助。

于 2014-10-04T06:42:29.060 回答