1

PHPMailer を使用して、入力データが電子メールで送信されるオンライン フォームを作成しました。ただし、現在受信している電子メールには、ユーザーが実際にフォームに入力した内容ではなく、変数が表示されています。以下は、私が受け取ったばかりのメールの例です。

Account Name: $AccountName
Delivery To: $DeliveryTo
Order No: $OrderNo
Del Date: $DelDate
Builder Name: $BuilderName
Delivery Instructions: $DeliveryInstructions
Contact Phone: $ContactPhone

アカウント名、電話番号などを入力しても、実際の入力ではなく、変数名 ($AccountName、$ContactPhone) が表示されていることに注意してください。以下に示すようにこれらの変数を設定したので、なぜこれが起こっているのかわかりません。どんな助けでも大歓迎です。

私のmail.phpで:

<?php
    require("/home/ange/public_html/angelasmith.com.au/staging/PHPMailer_5.2.2/class.phpmailer.php");

    $AccountName = $_POST['AccountName'];
    $DeliveryTo = $_POST['DeliveryTo'];
    $OrderNo = $_POST['OrderNo'];
    $DelDate = $_POST['DelDate'];
    $BuilderName = $_POST['BuilderName'];
    $DeliveryInstructions = $_POST['DeliveryInstructions'];
    $ContactPhone = $_POST['ContactPhone'];
    $totalsheets = $_POST['totalsheets'];
    $totalsqm = $_POST['totalsqm'];

    $c15 = $_POST['c15'];
    $d15 = $_POST['d15'];
    $e15 = $_POST['e15'];
    $f15 = $_POST['f15'];
    $h15 = $_POST['h15'];
    $i15 = $_POST['i15'];
    $j15 = $_POST['j15'];
    $k15 = $_POST['k15'];
    $l15 = $_POST['l15'];
    $m15 = $_POST['m15'];

    $c16 = $_POST['c16'];
    $d16 = $_POST['d16'];
    $e16 = $_POST['e16'];
    $f16 = $_POST['f16'];
    $h16 = $_POST['h16'];
    $i16 = $_POST['i16'];
    $j16 = $_POST['j16'];
    $k16 = $_POST['k16'];
    $l16 = $_POST['l16'];
    $m16 = $_POST['m16'];

    $mail = new PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host = "mail.mydomain.com.au";  // specify main and backup server
    $mail->Port = 25; 
    $mail->Username = "test@mydomain.com.au";  // SMTP username
    $mail->Password = "********"; // SMTP password

    $mail->From = "hello@mydomain.com.au";
    $mail->FromName = "*********";
    $mail->AddAddress("hello@mydomain.com.au");

                $mail->WordWrap = 50;                                 // set word wrap to 50 characters
                $mail->IsHTML(true);                                  // set email format to HTML

                $mail->Subject = "New Online Form Enquiry";

                $htmlBody = '<html>
                <head><title>Online Order Form</title></head><body>
                <p><b>Account Name:</b> $AccountName<br>
                <b>Delivery To:</b> $DeliveryTo<br>
                <b>Order No:</b> $OrderNo<br>
                <b>Del Date:</b> $DelDate<br>
                <b>Builder Name:</b> $BuilderName<br>
                <b>Delivery Instructions:</b> $DeliveryInstructions<br>
                <b>Contact Phone:</b> $ContactPhone<br>

                <table style="border:1px solid #ccc" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><strong>1700</strong></td>
                        <td><strong>2100</strong></td>
                        <td><strong>3000</strong></td>
                        <td><strong>3600</strong></td>
                        <td><strong>4200</strong></td>
                        <td><strong>4800</strong></td>
                        <td><strong>5400</strong></td>
                        <td><strong>6000</strong></td>
                        <td>m2</td>
                        <td>Count</td>
                    </tr>

                    <tr>
                        <td><strong>10 RE</strong></td>
                        <td>1200</td>
                        <td>$c15</td>
                        <td>$d15</td>
                        <td>$e15</td>
                        <td>$f15</td>
                        <td>$h15</td>
                        <td>$i15</td>
                        <td>$j15</td>
                        <td>$k15</td>
                        <td>$l15</td>
                        <td>$m15</td>
                    </tr>

                    <tr>
                        <td><strong>10 RE</strong></td>
                        <td>1350</td>
                        <td>$c16</td>
                        <td>$d16</td>
                        <td>$e16</td>
                        <td>$f16</td>
                        <td>$h16</td>
                        <td>$i16</td>
                        <td>$j16</td>
                        <td>$k16</td>
                        <td>$l16</td>
                        <td>$m16</td>
                    </tr>

                    <tr>
                        <td><strong>Span</strong></td>
                        <td>1200</td>
                        <td>$c17</td>
                        <td>$d17</td>
                        <td>$e17</td>
                        <td>$f17</td>
                        <td>$h17</td>
                        <td>$i17</td>
                        <td>$j17</td>
                        <td>$k17</td>
                        <td>$l17</td>
                        <td>$m17</td>
                    </tr>

                    <tr>
                        <td><strong>Span</strong></td>
                        <td>1350</td>
                        <td>$c18</td>
                        <td>$d18</td>
                        <td>$e18</td>
                        <td>$f18</td>
                        <td>$h18</td>
                        <td>$i18</td>
                        <td>$j18</td>
                        <td>$k18</td>
                        <td>$l18</td>
                        <td>$m18</td>
                    </tr>

                    <tr>
                        <td><strong>13 RE</strong></td>
                        <td>1200</td>
                        <td>$c19</td>
                        <td>$d19</td>
                        <td>$e19</td>
                        <td>$f19</td>
                        <td>$h19</td>
                        <td>$i19</td>
                        <td>$j19</td>
                        <td>$k19</td>
                        <td>$l19</td>
                        <td>$m19</td>
                    </tr>

                    <tr>
                        <td><strong>13 RE</strong></td>
                        <td>1350</td>
                        <td>$c20</td>
                        <td>$d20</td>
                        <td>$e20</td>
                        <td>$f20</td>
                        <td>$h20</td>
                        <td>$i20</td>
                        <td>$j20</td>
                        <td>$k20</td>
                        <td>$l20</td>
                        <td>$m20</td>
                    </tr>

                    <tr>
                        <td><strong>10 WR</strong></td>
                        <td>1200</td>
                        <td>$c21</td>
                        <td>$d21</td>
                        <td>$e21</td>
                        <td>$f21</td>
                        <td>$h21</td>
                        <td>$i21</td>
                        <td>$j21</td>
                        <td>$k21</td>
                        <td>$l21</td>
                        <td>$m21</td>
                    </tr>

                    <tr>
                        <td><strong>10 WR</strong></td>
                        <td>1350</td>
                        <td>$c22</td>
                        <td>$d22</td>
                        <td>$e22</td>
                        <td>$f22</td>
                        <td>$h22</td>
                        <td>$i22</td>
                        <td>$j22</td>
                        <td>$k22</td>
                        <td>$l22</td>
                        <td>$m22</td>
                    </tr>

                    <tr>
                        <td><strong>13 WR</strong></td>
                        <td>1200</td>
                        <td>$c23</td>
                        <td>$d23</td>
                        <td>$e23</td>
                        <td>$f23</td>
                        <td>$h23</td>
                        <td>$i23</td>
                        <td>$j23</td>
                        <td>$k23</td>
                        <td>$l23</td>
                        <td>$m23</td>
                    </tr>

                    <tr>
                        <td><strong>Villaboard 6mm</strong></td>
                        <td>1200</td>
                        <td>$c24</td>
                        <td>$d24</td>
                        <td>$e24</td>
                        <td>$f24</td>
                        <td>$h24</td>
                        <td>$i24</td>
                        <td>$j24</td>
                        <td>$k24</td>
                        <td>$l24</td>
                        <td>$m24</td>
                    </tr>

                    <tr>
                        <td><strong>Villaboard 6mm</strong></td>
                        <td>1350</td>
                        <td>$c35</td>
                        <td>$d35</td>
                        <td>$e35</td>
                        <td>$f35</td>
                        <td>$h35</td>
                        <td>$i35</td>
                        <td>$j35</td>
                        <td>$k35</td>
                        <td>$l35</td>
                        <td>$m35</td>
                    </tr>


                </table>

                <p><h3>Total Sheet Count:</h3> $totalsheets<br>
                <h3>Total Square Metres:</h3> $totalsqm</p>

                ';

                $mail->Body = $htmlBody;
                $mail->AltBody = $textBody;

                if(!$mail->Send())
                {
                   echo "Message could not be sent. <p>";
                   echo "Mailer Error: " . $mail->ErrorInfo;
                   exit;
                }

                echo "Message has been sent";
                ?>
4

1 に答える 1

2

一重引用符を使用して文字列変数を宣言する場合は、次のように変数を連結するだけです。

$htmlBody = '<html>
    <head><title>Online Order Form</title></head><body>
    <p><b>Account Name:</b> '.$AccountName.'<br>
    <b>Delivery To:</b> '.$DeliveryTo.'<br>
    <b>Order No:</b> '.$OrderNo.'<br>
    <b>Del Date:</b> '.$DelDate.'<br>
    <b>Builder Name:</b> '.$BuilderName.'<br>
    <b>Delivery Instructions:</b> '.$DeliveryInstructions.'<br>
    <b>Contact Phone:</b> '.$ContactPhone.'<br>
    ...
    ';

それ以外の場合は、変数を値に置き換えたい場合は、二重引用符を使用して文字列変数を宣言する必要があります。

$htmlBody = "<html>
    <head><title>Online Order Form</title></head><body>
    <p><b>Account Name:</b> $AccountName<br>
    <b>Delivery To:</b> $DeliveryTo<br>
    <b>Order No:</b> $OrderNo<br>
    <b>Del Date:</b> $DelDate<br>
    <b>Builder Name:</b> $BuilderName<br>
    <b>Delivery Instructions:</b> $DeliveryInstructions<br>
    <b>Contact Phone:</b> $ContactPhone<br>
    ...
    ";
于 2013-01-21T00:11:02.407 に答える