我正在使用PHPmailer发送电子邮件。我已经创建了一个表单,您可以输入一些详细信息(包括电子邮件地址)。单击submit/generate后,我想使用表单详细信息修改电子邮件的内容。电子邮件消息应显示为html电子邮件。然而,我就是不能让我的表单正确显示,或者让我的html-email正确发送。
表单代码(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>我曾设想在提交时,所需的电子邮件消息将根据输入字段进行更改,然后发送到在电子邮件输入字段中键入的地址。
发布于 2017-03-13 16:42:05
我不确定这行代码是否如预期的那样工作:
$emailmessage = require 'mail.php';您的mail.php应该如下所示:
$emailmessage = "
<!DOCTYPE html>
<html>
<body>
<p>First Name:".$_POST['firstname']."</p>
<p>Last Name: ".$_POST['lastname']."</p>
</body>
</html>";然后只使用
require "mail.php" 在你的代码的第二行。您还应该将"form“标记添加到HTML-form中。
https://stackoverflow.com/questions/42759321
复制相似问题