如何使用php将包含所有注册详细信息的邮件发送到固定的邮件地址

如何使用php将包含所有注册详细信息的邮件发送到固定的邮件地址,php,html,Php,Html,我有一份登记表: <h2>PHP Form Validation Example</h2> <form method="post" action="sendmail.php"> Name: <input type="text" name="name"> <br><br> E-mail: <input type="text" name="email"> <br><br> Website:

我有一份登记表:

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
PHP表单验证示例
姓名:


电邮:

网站:

评论:

我编写了php代码,可以像这样发送邮件:

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
<?php
 $name = $_POST['name'];
 $to = $_POST['email'];
 $msg = $_POST['comment'];
 sendMail($to);
 function sendMail($to){
 $subject = "Thanks for registring.";
 $message = "We are glad that you have posted your problems with us.";
 //$header = "From:".$to;

  $headers = array(
  'From' => $email,
  'To' => $to,
  'Subject' => $subject
  );

  $smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.live.com',
    'port' => '587',
    'auth' => true,
    'username' => 'USERNAME',
    'password' => 'PASSWORD'
  ));

  $pmailing = $smtp->send($to, $headers, $body);
 //$retval = mail ($to,$subject,$message,$header);
 //$mmsg = 'Receiver: mymail@gmail.com';
 if( $pmailing == true )  
 {
  echo "Message sent successfully...";
  //$mmsg = "Mail sent.";
 }
 else
 {
  echo "Message could not be sent...";
  //$mmsg = "Mail not send.";
  echo'<script> window.location="re_enter.html"; </script> ';
 }
}
?>


这表明“邮件”是不可接受的。所以建议我,我已经用你共享的代码编辑了我的代码。我是否需要添加任何库或类似库来执行此SMTP代码。

用于在xmapp Localhost上配置邮件

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
转到xampp/php/php.ini打开并搜索

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
 [mail function]
    SMTP = mail.yourserver.com
    smtp_port = 25
然后保存文件并重新启动apache 有关更多信息:

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
用于发送php的函数是

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
$retval = mail($to, $subject, $message);
if($retval)
// your stuff here

或者使用

尝试此代码。这是演示代码。根据您的要求进行更改

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>
<?php
$from = $_POST['EmailAddr']; //email id of applicant.
$to = 'YOUR MAIL ID';
$subject = 'Call Back Enquiry';
$fullname=$_POST['Name'];
$mobile=$_POST['PhoneMobile'];
$email=$_POST['EmailAddr'];
$message=$_POST['YourMessage'];
$body="Full Name:".$fullname."\n\n"."Mobile:".$mobile."\n\n"."Email:".$email."\n\n"."Message:".$message;

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'YOUR MAIL ID',
        'password' => 'PASSWORD'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
   // echo('<p>Message successfully sent!</p>');
}
?>


您必须在服务器中配置SMTP以使用邮件功能…hw配置SMTP am以使用XAMP服务器执行此代码何谓$retval以及您发送邮件的位置?Rakesh,$retval是一个可变的更好的解决方案->具有增强的选项和调试。hi Rakesh,我已经指定了SMTP=SMTP.gmail.com,但apache仍然无法接收任何邮件,只能接收带有message send的邮件successful@Pallavipradeep您需要填写更多设置:。您尚未填写任何用户凭据<代码>SMTP=SMTP.gmail.com;smtp_端口=587;sendmail\u from=[您的\u gmail\u用户名]@gmail.com;sendmail\u path=“\”C:\xampp\sendmail\sendmail.exe\”-t“Rakesh,在对代码进行特定更改后,它不工作,它在“邮件”字处抛出错误。检查我编辑的代码我是如何写这段代码的