2016-04-17 8 views
-1

私は$mail->get_include_contents()を使用している人を見ましたが、その仕組みが正確にわかりません。PHPMailer変数を渡す方法

私は電子メールでアカウントを有効にします。私はユーザー名、ランダムキー、電子メールなどを渡すテンプレートPHP、htmlまたはtplを持っています。私はすべてのプロジェクトでSmartyを使用していると考えてください。私gmail.phpで

私が持っている:

$mail->msgHTML(file_get_contents(dirname(__FILE__).'/MailActivation.php'), $variables); 

誰かが、私はそれを行うことができるか私に説明できますか?

答えて

0

ファイルは、指定されたファイルパスに基づいてインクルードされます。指定されていない場合、include_pathが指定されます。ファイルがインクルードパスに見つからない場合、インクルードは最後に呼び出し元のスクリプトのディレクトリと現在の作業ディレクトリをチェックしてから失敗します。インクルードコンストラクトは、ファイルが見つからない場合に警告を出します。これはrequireとは異なる動作であり、致命的なエラーが発生します。

$mail->Body = get_include_contents('sample.php', $variable); 

をsample.php

最後に
<table width='600px' cellpadding='0' cellspacing='0'> 
<tr><td bgcolor='#eeeeee'><img src='logo.png' /></td></tr> 
<tr><td bgcolor='#ffffff' bordercolor='#eeeeee'> 
<div style='border:1px solid #eeeeee;font-family:Segoe UI,Tahoma,Verdana,Arial,sans-serif;padding:20px 10px;'> 
<p>Variable one is <?php echo $one; ?>.</p> 
<p>Variable two is <?php echo $two; ?>.</p> 
<p>Thanks</p> 
</div> 
</td></tr> 
</table> 
1

¡!私はそれはdoesnのだと思う

Lorem ipsum %testusername% dolor sit amet, consectetur adipiscing elit. Integer nulla elit, mattis non leo in, ornare interdum ante. Proin eget velit purus. Sed convallis lectus sed libero ornare, sit amet pharetra nisi facilisis. Cras fermentum nulla quis purus egestas, in accumsan nisl dictum. Donec in nisi vel enim pretium posuere at nec ante. Mauris tempus velit vel urna commodo accumsan. %testemail% 

:私はちょうどhtmlファイル、どこで私はちょうど置く変数を挿入したいを作成し、私のActivationTemplate.htmlで

<?php 

    date_default_timezone_set('Etc/UTC'); 

    require(dirname(__FILE__).'/../PHPMailerAutoload.php'); 
    require_once (dirname(__FILE__).'/../../controller/SignUpController.php'); 

    $variables = [$username, $email, $randomkey]; 

    //Create a new PHPMailer instance 
    $mail = new PHPMailer; 

    //Tell PHPMailer to use SMTP 
    $mail->isSMTP(); 

    //Enable SMTP debugging 
    // 0 = off (for production use) 
    // 1 = client messages 
    // 2 = client and server messages 
    $mail->SMTPDebug = 0; 

    //Ask for HTML-friendly debug output 
    $mail->Debugoutput = 'html'; 

    //Set the hostname of the mail server 
    $mail->Host = 'smtp.gmail.com'; 
    // use 
    // $mail->Host = gethostbyname('smtp.gmail.com'); 
    // if your network does not support SMTP over IPv6 

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 
    $mail->Port = 587; 

    //Set the encryption system to use - ssl (deprecated) or tls 
    $mail->SMTPSecure = 'tls'; 

    //Whether to use SMTP authentication 
    $mail->SMTPAuth = true; 

    //Username to use for SMTP authentication - use full email address for gmail 
    $mail->Username = "your_email"; 

    //Password to use for SMTP authentication 
    $mail->Password = "your_password_email"; 

    //Set who the message is to be sent from 
    $mail->setFrom('user_email_from', 'title_to_display'); 

    //Set an alternative reply-to address: it's optional 
    //$mail->addReplyTo('user_email_reply', 'user_email_name'); 

    //Set who the message is to be sent to 
    $mail->addAddress($email, $firstname . " " . $lastname); 

    //Set the subject line 
    $mail->Subject = 'Subject'; 

// Settin variables  
    $message = file_get_contents(dirname(__FILE__).'/MailActivation.html'); 
    $message = str_replace('%testusername%', $username, $message); 
    $message = str_replace('%testemail%', $email, $message); 
    $message = str_replace('%testrandomkey%', $randomkey, $message); 

    $mail->msgHTML($message); 

    //Replace the plain text body with one created manually 
    //$mail->AltBody = 'This is a plain-text message body'; 

    //Attach an image file 
    //$mail->addAttachment('images/phpmailer_mini.png'); 

// For sending an image inline 
    $mail->AddEmbeddedImage(dirname(__FILE__).'/images/frontimage.jpg', 'front', 'images/frontimage.jpg'); 

    //send the message, check for errors 
    if (!$mail->send()) { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 


      echo "Message sent!"; 
     } 
?> 

これは結果でしたあなたがPHPのテンプレートやHTMLを使用する場合は問題ありません。

関連する問題