2017-01-30 5 views
0

私はいくつかのSESSION変数をPHPメール関数に渡して、その情報を持つユーザに送ることができます。電子メールシステムは機能しますが、ユーザーに届いた電子メールには空の変数があります。PHPメールにvarsを渡そうとしています

//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?> &euro;</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: 
    // [email protected] 
    mail("[email protected]", "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>&nbsp;</p><p>Thank you,<br>ABC-Gym</p>"; 

私はそれを修正するために何かを試してきました。 何かアドバイスがありますか?

おかげで、 アンドレアス・M.

+2

任意の差出人フィールドを使用して電子メールをなりすますことは、送信する評判を破壊する良い方法です。あなたはいつもあなたが管理しているアドレスから送信し、SPFレコードを設定することができます。元の送信者に返信できるようにするには、「Reply-To」フィールドを設定します。 – tadman

答えて

0

[OK]を私はいくつかの試行錯誤の後にこれを考え出しました。私はphpのmail()関数とemail.phpのPHPMailerオプションを混在させていました。また、ユーザーの入力から取得した電子メールアドレスに電子メールを送信しています。

これは、私が「フォーム」と「メール()」のための私のresponse.phpページで変更するものである:ここでは、phpmailerの私のemail.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: 
     // [email protected] 
     mail("$email", "ABC Payment Submission", $message, "From: [email protected]"); 
     } 
    ?> 

のみの変更は(コメントを参照しています):

// $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; 

作業中です!

+0

'mail()'とphpMailerを同時に使用していますか?確かに、phpMailerの全体的なポイントは、あなたが以前のclunkyな 'mail()'関数を使わなくて済むようにすることです。コード内にphpMailerがある場合は、それをすべて使用してください。 – Simba

+0

@simba、今私は実現しました。エラーから学ぶ、ありがとう。 – Gumstic

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: 
    // [email protected] 
    mail("[email protected]", "Online Submission",$message, "From: $email"); 
    } 
?> 

あなたは$メッセージ変数やメールにそれを送信する()関数に、 "......ありがとう" 割り当てますメールを送信します。

$ mail->ボディラインは実行されず、空変数の理由があります。 使用

$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>&nbsp;</p><p>Thank you,<br>ABC-Gym</p>"; 
+0

Mohd、 私はあなたが提案したものを試しましたが、引き続き同じ空でない変数を試しました。 response.php(送信者)ページとemail.php自体の両方に$ messageがあることに注意しましょう。 – Gumstic

+0

$ member1とemail.phpの他のすべての変数にアクセスできますか?私のmail.phpコードを見てくださいhttp://pastebin.com/bfCLFhWe –

+0

いいえ、私はemail.phpの変数を取得しません - また、私のファイルは$ mail-> From = $ email;あなたのことを見てから混乱します。どうすればいいですか? – Gumstic

関連する問題