2

这是我所拥有的:`

<?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 文档中输入表单。

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

任何帮助将不胜感激

4

4 回答 4

3

你可以使用:

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

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

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

这使用 a .= 添加到现有的 Body。

于 2013-07-24T19:40:24.290 回答
2

试试这个方法...

$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。

于 2013-07-24T19:43:22.727 回答
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 字符串连接: http: //php.net/manual/en/language.operators.string.php

于 2013-07-24T19:41:14.553 回答
0

您可以将这些$_POST字段连接成一个字符串,然后$mail->Body使用 php 连接运算符将其传递给,.如下所示:

$mail->Body = $_POST['one'].$_POST['two'].$_POST['three']; // etc...
于 2013-07-24T19:41:24.073 回答