0

私は何日もの間、うまく機能するPHPMailerコードをWordPressプラグインにマージしようとしましたが、成功しませんでした. 1つのコンタクトフォーム送信で2つの別々の電子メールを送信するという目標を達成する限り、私は別のルートを喜んで下ります。2、フォームに入力されたメッセージを固定メールアドレスに送信します。

これを解読するのに役立つあなたの意見は大歓迎です。

添付の JSFiddle を見つけてください。もちろん、これは PHP コードであり、機能しませんが、ここに大量のコードを貼り付けるよりもはるかに優れていると感じました。

既存の動作中の Mailer コードはうまく動作し、私が達成したかったすべてのことを実行しました (上記で説明しました)。統合したいPHPMailerコードを以下に示します。

http://jsfiddle.net/CUMzq/

<?php

      $field_fullname = $_POST['cf_mercury']; // cf_name is a convention used by the HTML form
      $field_email = $_POST['cf_jupiter'];
      $field_message = $_POST['cf_uranus'];

    require_once('class.phpmailer.php');

    // E-Mail to Client

    $mail             = new PHPMailer(); // defaults to using php "mail()"

    $body = "Hello $field_fullname,<br><br>\r\nThank you for contacting the BUSINESS. We will endeavour to contact you as soon as possible. In the meantime, we have attached a PDF booklet which will provide you with more information.<br><br>\r\nKind regards<br><br>\r\nBUSINESS";

    $mail->SetFrom('example@email.co.uk', 'BUSINESS'); 

    $mail->AddReplyTo('example@email.co.uk', 'BUSINESS');

    $address = $field_email;
    $mail->AddAddress($address, $field_fullname);

    $mail->Subject    = 'Auto-Response: Thank you for contacting the BUSINESS, '.$field_fullname;

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->MsgHTML($body);

    $mail->AddAttachment("/url/path/to/demo/business/booklet.pdf");      // attachment
    $mail->AddAttachment(""); // attachment

    $sent = $mail->Send();


    // E-Mail to Company

    $mail2 = clone $mail;

    $mail2             = new PHPMailer(); // defaults to using php "mail()"

    $body = $field_message;

    $mail2->SetFrom($field_email, $field_fullname); 

    $mail2->AddReplyTo($field_email, $field_fullname);

    $address = "example@email.co.uk";
    $mail2->AddAddress($address, "BUSINESS");

    $mail2->Subject    = 'Enquiry via the ETAP Centre website from '.$field_fullname;

    $mail2->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail2->MsgHTML($body);

    $mail2->AddAttachment(""); // attachment - leave incase they are needed in the future
    $mail2->AddAttachment(""); // attachment

    $sent = $mail2->Send();

    if($sent) {
      { ?>
<script language="javascript" type="text/javascript">
            alert('Thank you for contacting the BUSINESS. We will contact you shortly.');
            window.location = 'index.html';
        </script>
<?php
    }
    } else {
      ?>
<script language="javascript" type="text/javascript">
            alert('Message failed. Please, send your email to example@email.co.uk');
            window.location = 'index.html';
        </script>
<?php
    }
    ?>

すべての助けをいただければ幸いです。質問を明確にしたり、理解を深めるために何かできることがあれば、お知らせください。ありがとうございました!

4

1 に答える 1

1

wp_mail を使用してメールの添付ファイルを送信できます-

<?php
  $attachments = array(WP_CONTENT_DIR . '/uploads/file_to_attach.zip');
  $headers = 'From: My Name <myname@mydomain.com>' . "\r\n";
  wp_mail('test@test.com', 'subject', 'message', $headers, $attachments);
?>

HTML コンテンツを送信するには、これを使用します。

<?php
add_filter( 'wp_mail_content_type', 'set_html_content_type' );
wp_mail( 'me@example.net', 'The subject', '<p>The <em>HTML</em> message</p>' );
remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); // reset content-type    to to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
function set_html_content_type()
{
return 'text/html';
}
?>

詳細については、次のリンクを参照してください。

http://codex.wordpress.org/Function_Reference/wp_mail

于 2013-05-17T09:18:44.077 に答える