这就是我所拥有的:`
<?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 = "email@email.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "email@email.com";
$mail->FromName = $_POST["name"];
$mail->AddAddress("other@other.com"); // 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-&gt; Body之后放置多个$ _POST时它不起作用。
任何帮助将不胜感激
答案 0 :(得分:1)
您可以使用:
$mail->Body = $_POST["one"].$_POST["two"];
这使用句点来分隔不同的变量,或者您可以使用:
$mail->Body = $_POST["one"];
$mail->Body .= $_POST["two"];
这使用.=
添加到现有的Body。
答案 1 :(得分:1)
以这种方式试试......
$mail->Body = "This is starting ".{addslashes($_POST['one'])}. " This is Two. ".{addslashes($_POST['two'])}." This is END";
或
$mail->Body = "This is starting";
$mail->Body .= addslashes(trim($_POST['one']));
$mail->Body .= " This is Two. ";
$mail->Body .= addslashes(trim($_POST['two']));
$mail->Body .= "This is END";
'' (DOT)用作连接运算符。确保检查任何SQL INJECTION。
答案 2 :(得分:0)
$mail->Body = $_POST["one"] . $_POST["two"] . $_POST["three"];
或更好,也许:
$one = isset($_POST["one"]) ? $_POST["one"] : NULL;
$two = isset($_POST["two"]) ? $_POST["two"] : NULL;
$three = isset($_POST["three"]) ? $_POST["three"] : NULL;
$body = $one . $two . $three;
$mail->Body = $body;
PHP String Concatenation:http://php.net/manual/en/language.operators.string.php
答案 3 :(得分:0)
您可以将$_POST
字段连接成一个字符串,然后使用php连接运算符$mail->Body
传递给.
,如下所示:
$mail->Body = $_POST['one'].$_POST['two'].$_POST['three']; // etc...