我已经检查了论坛以找到答案,但我没有成功,其他问题专门针对PHPMailer的某些部分,但我的更为一般。所以我希望没有人会像我在学习曲线那样将我的问题标记为重复。
我正在开发一个PHP项目。工作原理是用户进入页面并在表单(文本编辑器)中写入一些注释,然后单击发送按钮。我能够在我的电子邮件中收到他的消息。我已将密码和主机设置为空,原因很明显,但稍后它将成为我自己域名的真实电子邮件。
问题是这里有两个问题:
请您提供有用的建议或示例代码。谢谢。
if($_POST['mode']=='send'){
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "myhost"; // SMTP server
//$mail->SMTPSecure = 'ssl';
$mail->From = "my email";
$mail->port = '26'; // can also change to 465
$mail->SMTPAuth = true;
$mail->Username= "my email";
$mail->Password = "my password";
$mail->AddAddress("my email");
$Name = mysql_real_escape_string($_POST['part_fname']); //this code is not getting the name and email
$Email = mysql_real_escape_string($_POST['part_email']);
$mail->Subject = "New Bug Report";
$mail->Body = "User Information, Name = " . $Name . " || Email = " . $Email; // I want to get the user's message not a static message!
$mail->WordWrap = 50;
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
$message = 'Thanks for your suggestion';
}
}
以下是html中的表单:
<form role="form" name="Form2" action="" method="post" class="form-horizontal">
<textarea name="bug" cols="100" rows="15" id="textarea" placeholder="Enter text ..."></textarea>
<input name="mode" value="send" type="hidden">
<p style="margin-top:5px;"><input type="reset" value="Clear Text!" class="btn btn-danger"> <button type="submit" class="btn btn-primary">Send report</button></p>
</form>
答案 0 :(得分:1)
删除mysql_real_escape_string
它需要连接到mysql。
$Name = $_POST['part_fname'];
$Email = $_POST['part_email'];
$message= $_POST['bug'];//add this to get the textarea value
然后将值附加到正文:
$mail->Body = "User Information, Name = " . $Name . " || Email = " . $Email;
$mail->Body .= "Message: ".$message;
如果你想要会话
用户登录时间:
session_start();
$_SESSION['part_fname'] = $Name;
$_SESSION['part_email'] = $Email;
发送电子邮件时:
session_start();
$Name = $_SESSION['part_fname'];
$Email = $_SESSION['part_email'];
$message= $_POST['bug'];
答案 1 :(得分:1)
到表单,您需要添加名称和电子邮件的字段,如下所示:
<input name="part_fname" value="" type="text">
<input name="part_email" value="" type="text">
然后改变代码:
$Name = $_POST['part_fname'];
$Email = $_POST['part_email'];
$message= $_POST['bug'];// textarea value
$mail->Body = "User Information, Name = " . $Name . " || Email = " . $Email;
$mail->Body .= "Message: ".$message;