PHPMailer - 正文中有多个 $_POST

标签 php phpmailer

这是我所拥有的:`

<?php
require("/Library/WebServer/Documents/phpmailer/PHPMailer_v5.1/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "host";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caafa7aba3a68aafa7aba3a6e4a9a5a7" rel="noreferrer noopener nofollow">[email protected]</a>";  // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30555d51595c70555d51595c1e535f5d" rel="noreferrer noopener nofollow">[email protected]</a>";
$mail->FromName = $_POST["name"];

$mail->AddAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deb1aab6bbac9eb1aab6bbacf0bdb1b3" rel="noreferrer noopener nofollow">[email protected]</a>");                  // name is optional


$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML


$mail->Subject = $_POST["subject"];
$mail->Body = $_POST["one"];

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>`

我试图在电子邮件正文中包含多个 $_POST,因为我想要从 HTML 文档获取表单输入。

例如,我希望在正文中包含来自“one”等的输入,但是当我尝试在 $mail->Body 之后放置多个 $_POST 时,它不起作用。

任何帮助将不胜感激

最佳答案

您可以使用:

$mail->Body = $_POST["one"].$_POST["two"];

这使用句点来分隔不同的变量,或者您可以使用:

$mail->Body = $_POST["one"];
$mail->Body .= $_POST["two"];

这使用 .= 添加到现有的正文。

关于PHPMailer - 正文中有多个 $_POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17843339/

相关文章:

php - SQL Select 对多列进行计数并排序

php - 使用 PHPMailer 发送电子邮件和旋转图像

PHPMailer 生成 PHP 警告 : stream_socket_enable_crypto(): Peer certificate did not match expected

php - SMTP 错误 : Failed to connect to server: Connection refused (111) ERROR MESSAGE

Phpmailer 不在同一域上发送电子邮件

php - 需要从 quickbooks 在线发送发票作为邮件

php - 如何避免在 PHP 中重复 MySQL 查询代码的类似部分?

php - PHP 中有一个好的基于角色的工作流引擎吗?

php - 背景切换器?

php - 在 CodeIgniter for Oracle 中设置数据库模式