【发布时间】:2017-08-03 05:09:05
【问题描述】:
我正在使用 PHPmailer 发送我的电子邮件。我创建了一个表单,您可以在其中输入一些详细信息(包括电子邮件地址)。单击提交/生成后,我想使用表单详细信息修改电子邮件的内容。电子邮件消息应显示为 html 电子邮件。但是,我只是无法让我的表单正确显示或让我的 html 电子邮件正确发送。
表单代码(index.php): `
<?php
//PHP mailer code
require 'PHPmailer/PHPMailerAutoload.php';
$emailmessage = require 'mail.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
if (isset($_POST['submit'])) {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'email@email.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('email@email.com', 'Me');
$mail->addAddress($_POST['emailrecipients'], $_POST['client']); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['callid'].' | Customer Feedback';
$mail->Body = $emailmessage;
$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';
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form>
<input type="text" id="firstname" name="firstname" placeholder="John" />
<input type="text" id="lastname" name="lastname" placeholder="Doe" />
<input type="email" id="email" name="email" placeholder="email@email.com" />
<button type="submit" name="submit">Generate</button>
</form>
</body>
</html>`
电子邮件代码(mail.php):
<!DOCTYPE html>
<html>
<body>
<p>First Name: <?php $_POST['firstname']; ?></p>
<p>Last Name: <?php $_POST['lastname']; ?></p>
</body>
</html>
我曾设想,在提交时,所需的电子邮件将根据输入字段进行更改,然后发送到在电子邮件输入字段中键入的地址。
【问题讨论】:
-
您的 HTML 中没有
form。
标签: php email phpmailer html-email