当用户在同一页面上提交电子邮件时,我一直在尝试设置"谢谢" 消息,以便消息显示在提交表单下方以我选择的颜色。
但是,到目前为止,我的代码只提交了电子邮件而没有感谢您 消息,似乎没有回复带有反馈ID的p标签。
那么如何修改我的代码,以便在提交电子邮件时将ID为#feedback的p-tag显示为感谢信息?
$email = $_REQUEST['email'] ;
require("C:/inetpub/folder/PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.comcast.net";
$mail->SMTPAuth = true;
$mail->Username = "username@comcast.net"; // SMTP username
$mail->Password = "**********"; // SMTP password
$mail->SMTPSecure = 'TLS';// Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;
$mail->From = $email;
$mail->setFrom('$email', 'Guest');
$mail->addAddress('admin@mydomain.com', 'Support');
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "A new member wishes to be added";
$mail->Body = $email;
$mail->AltBody = $email;
$mail2 = new PHPMailer();
$mail2->IsSMTP();
$mail2->Host = "smtp.comcast.net";
$mail2->SMTPAuth = true;
$mail2->Username = "username@comcast.net"; // SMTP username
$mail2->Password = "*********"; // SMTP password
$mail2->SMTPSecure = 'TLS';
$mail2->Port = 25;
$mail2->setFrom('support@mydomain.com', 'Support');
$mail2->AddAddress("$email");
$mail2->addReplyTo('support@mydomain.com');
$mail2->WordWrap = 50;
mail($to, $subject, $message, $headers);
$mail2->Subject = "Thanks for signing up";
$headers = "From: " . strip_tags($_POST['admin@mydomain.com']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['loo@mydomain.com']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$mail2->IsHTML(true);
$message .= '<p style="font-size:16px; color:#000; font-weight:bold;">Welcome,</p> ';
$message .= "<p style='line-height:1.6; color:#666; font-size:16px;'>You have been added to.</p> " ;
$message .= "</body></html>";
$mail2->Body = $message;
$mail2->AltBody = $message;
if (!$mail2->Send()) {
$feedback = 'Thanks for the email';
}
if (!$mail->Send()) {
$feedback = 'Thanks for the email';
}
?>
html:
<div class="guestlist">
<form action="?" method="post">
<input type="email" title="Enter Email Address" class="emailaddress" name="email" placeholder="Enter your Email Address" />
<button class="button" title="Submit Email to Guestlist" name="submit" value="Submit" type='submit'>Join</button>
<p id="feedback"> <?php echo $feedback; ?> </p>
</form>
</div>
</div>
答案 0 :(得分:0)
您应该阅读PHP手册,以便基本了解如何解释和编译代码以及将哪些内容作为输出发送。
feedback
变量为空的html; feedback
变量现在包含一个值,但HTML页面不会重新加载,因此保持不变。重新加载发送feedback
的HTML页面或使用ajax并听取答案:
$("button[name=submit]").on("click",function(){
type: "post",
url: mail.php,
success: function(serverResponse){
$("#feedback").html(serverResponse);
}
});
在这种情况下,您应该echo $feedback;
答案 1 :(得分:0)
如果电子邮件成功,我不会看到如何设置$反馈。
if (!$mail2->Send()) {
$feedback = 'Thanks for the email';
}
if (!$mail->Send()) {
$feedback = 'Thanks for the email';
}
对我说如果不成功。