Javascript I';I’我不知道如何通过电子邮件发送表格
在我的网站底部有一个“发送消息”按钮。我想它采取的信息和联系信息(电子邮件,姓名),并发送到我的电子邮件地址。我怎么可能这么做?顺便说一句,我是这个网站的新手。您可以使用PHP邮件功能Javascript I';I’我不知道如何通过电子邮件发送表格,javascript,php,html,email,Javascript,Php,Html,Email,在我的网站底部有一个“发送消息”按钮。我想它采取的信息和联系信息(电子邮件,姓名),并发送到我的电子邮件地址。我怎么可能这么做?顺便说一句,我是这个网站的新手。您可以使用PHP邮件功能 使用可以使用默认功能,也可以使用(Mail send helper)。两者都是安全和正确的。但是,如果您需要一些其他的东西,那么使用PHPMailer 1。使用PHP的mail()函数,这是可能的。请记住,邮件功能在本地服务器中不起作用 <?php $to = 'nobody@example.c
使用可以使用默认功能,也可以使用(Mail send helper)。两者都是安全和正确的。但是,如果您需要一些其他的东西,那么使用PHPMailer
1。使用PHP的mail()函数,这是可能的。请记住,邮件功能在本地服务器中不起作用
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: from@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
注意:如果使用SMTP,则需要在本地服务器上配置SMTP。看看这个类似的例子
2。您也可以在上使用PHPMailer类
它允许您透明地使用邮件功能或使用smtp服务器。它还处理基于HTML的电子邮件和附件,因此您不必编写自己的实现
以下是上一页的示例:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('webmaster@example.com', 'Webmaster User'); // Add a recipient
$mail->addAddress('webmaster@example.com'); // Name is optional example
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}