我正在尝试将一些SESSION变量传递给PHP邮件功能,以便可以使用该信息将其发送给用户。电子邮件系统有效,但到达用户的结果电子邮件中包含空变量。
//Start the session and add the variables to it (these are viewed on page before sending email out):
<?php
session_start();
// Continue the session
// retrieve session data
$amount = $_SESSION["vprice"];
$type = $_SESSION["vtype"];
$member = $_SESSION["vmember"];
//Variables viewed on the page:
<p style="text-align: center;">
Date: <?= date("Y/m/d")?><br>
Member ID: <?= $member?><br>
Order ID: <?= $abcOrderID?><br>
Order Type: <?= $type?><br>
Amount: <?= $amount?> €</p>
// Get users email address to send to:
<form method="post" action="email.php">
<p style="text-align: center;">
Send Confirmation E-mail to: <input type="text" name="email" value="" /></p>
<p style="text-align: center;"><input type="submit" name="submit" value="Send" /></p>
</form>
//Send the email using PHP mail()
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$email = $_REQUEST['email'] ;
$message = "Thank you for ......" ;
// here we use the php mail function
// to send an email to:
// you@example.com
mail( "info@abc.com", "Online Submission",$message, "From: $email" );
}
?>
//In email.php I use the following to build the message:
$mail->Body = "<p>Dear Member {$member1},</p><p>We have received your<strong> ABC payment</strong> and the purchased amount of {$amount1} in EUR will appear in your bank statement under the name ABC Ltd. Please keep this e-mail as a receipt for your records.</p><p>If you have any concern regarding this transaction, please do not hesitate to contact us</a>.</p><p> </p><p>Thank you,<br>ABC-Gym</p>";
我一直在尝试各种各样的东西来解决它,但没有。 什么是错误的建议?
谢谢, 安德烈亚斯。
答案 0 :(得分:0)
在您的代码中
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$email = $_REQUEST['email'] ;
$message = "Thank you for ......" ;
// here we use the php mail function
// to send an email to:
// you@example.com
mail( "info@abc.com", "Online Submission",$message, "From: $email" );
}
?>
您正在为$ message变量分配“谢谢......”并将其发送到发送邮件的mail()函数。
$ mail-&gt;未执行的正文行,这就是空变量的原因。 使用
$message = "<p>Dear Member {$member1},</p><p>We have received your<strong> ABC payment</strong> and the purchased amount of {$amount1} in EUR will appear in your bank statement under the name ABC Sports Center Ltd. Please keep this e-mail as a receipt for your records.</p><p>If you have any concern regarding this transaction, please do not hesitate to contact us</a>.</p><p> </p><p>Thank you,<br>ABC-Gym</p>";
答案 1 :(得分:0)
好的,经过一番试错,我已经弄明白了。我混淆了php的mail()函数和email.php中添加的PHPMailer选项,我还应该注意到我将电子邮件发送到从用户输入中捕获的电子邮件地址。
这是我在“Form”和“mail()”的response.php页面中更改的内容:
<form method="post" action="email.php">
<p style="text-align: center;">
Send Confirmation E-mail to: <input type="text" name="email" value="" />
<textarea style="visibility: hidden" name="message" id="message" rows="1" cols="1">
<p>Dear Member (ID <?= $member ?>),</p><p>We have received your <strong>ABC payment</strong> for order #<?= $abcOrderID ?>|<?= $type ?> and the charged amount of <?= $amount ?> EURO will appear on your bank statement under the name ABC Ltd. Please keep this e-mail as a receipt for your records.</p><p>If you have any concern regarding this transaction, please do not hesitate to contact us</a>.</p><p>Thank you,<br>ABC Payments</p></textarea></p>
<p style="text-align: center;"><input type="submit" name="submit" value="Send" /></p>
</form>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
// here we use the php mail function
// to send an email to:
// you@example.com
mail( "$email", "ABC Payment Submission", $message, "From: no-reply@abc.com" );
}
?>
现在在PHPMailer的email.php中,这里是唯一的变化(见评论):
// $email and $message are the data that is being
// posted to this page (email.php) from our php form (response.php)
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
//...
// $message is the forms message we have set in response.php
// page. We set this variable at the top of this page with:
// $message = $_REQUEST['message'];
$mail->Body = $message;
$mail->AltBody = $message;
立即行动!