I';m:如何使用PHP邮件发送HTML表单
好的,所以我在过去几天里做了大量的研究,我被难倒了。我有XAMPP和PHP Mailer,我知道它们在本地都能正常工作 我还有一个HTML表单,我知道它在使用Hostgator web托管时工作正常。此HTML表单调用名为send_email.php的.php文件,该文件将表单内容发送到我的电子邮件 我的问题是:I';m:如何使用PHP邮件发送HTML表单,php,html,xampp,localhost,phpmailer,Php,Html,Xampp,Localhost,Phpmailer,好的,所以我在过去几天里做了大量的研究,我被难倒了。我有XAMPP和PHP Mailer,我知道它们在本地都能正常工作 我还有一个HTML表单,我知道它在使用Hostgator web托管时工作正常。此HTML表单调用名为send_email.php的.php文件,该文件将表单内容发送到我的电子邮件 我的问题是: 使用PHPMailer在我的本地主机(XAMPP)上发送这个HTML表单的新的.php代码(粗略地说)是什么 如何在HTML文件中调用新的.php文件 对于这个HTML表单和php M
<!-- THE SUBMISSION FORM -->
<div class="container">
<form id="contact" action="send_email.php" method="post">
<h3>Apply Today!</h3>
<h4></h4>
<fieldset>
<input placeholder="Full Name" type="text" name="name" tabindex="1" required autofocus>
</fieldset>
<fieldset>
<input placeholder="Telephone Number" type="tel" name="telephone" tabindex="2" required>
</fieldset>
<fieldset>
<input placeholder="Email Address" type="email" name="email" tabindex="3" required>
</fieldset>
<fieldset>
<input placeholder="Subject" type="text" name="subject" tabindex="4" required>
</fieldset>
<fieldset>
<textarea placeholder="Type your Message Here...." name="message" tabindex="5" required></textarea>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending" tabindex="6">Submit</button>
</fieldset>
</form>
</div>
今天就申请!
提交
这是我正在使用的send_email.php文件(我知道该文件有效)
您根本不必更改代码;无论从何处运行,它都应该同样有效。只要您使用的是主机提供商允许的发送机制,例如,他们不阻止出站SMTP,它就可以正常工作。你试过了吗
除此之外,您的文件结构看起来有点不寻常。Composer为您安装PHPMailer,并在您请求时自动加载它,所以Composer还负责它的存储位置;您不需要创建自己的phpmailer
文件夹。如果您只托管一个站点,可能不需要将内容放在web根目录的子文件夹中,因此您可以使用更平坦的结构,如:
c:/Users/dylan/.bitnami/stackman/machines/xampp/volumes/root/htdocs/
index.php
send_email.php
vendor/
composer/
phpmailer
如果您托管多个站点,您通常会在
../htdocs/
中有多个文件夹,每个文件夹都具有类似的内部结构。您对php没有任何知识。
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
//$mail->Host = gethostbyname('smtp.gmail.com');
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'sender@gmail.com'; //SMTP username
$mail->Password = 'sender-password'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('receiver1@gmail.com', 'Mailer');
$mail->addAddress('receiver2@gmail.com', 'Dylan');
//Content
$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';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
$mail->setFrom('receiver1@gmail.com', 'Mailer');
$mail->addAddress('receiver2@gmail.com', 'Dylan');