私は何日もの間、うまく機能するPHPMailerコードをWordPressプラグインにマージしようとしましたが、成功しませんでした. 1つのコンタクトフォーム送信で2つの別々の電子メールを送信するという目標を達成する限り、私は別のルートを喜んで下ります。2、フォームに入力されたメッセージを固定メールアドレスに送信します。
これを解読するのに役立つあなたの意見は大歓迎です。
添付の JSFiddle を見つけてください。もちろん、これは PHP コードであり、機能しませんが、ここに大量のコードを貼り付けるよりもはるかに優れていると感じました。
既存の動作中の Mailer コードはうまく動作し、私が達成したかったすべてのことを実行しました (上記で説明しました)。統合したいPHPMailerコードを以下に示します。
<?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
}
?>
すべての助けをいただければ幸いです。質問を明確にしたり、理解を深めるために何かできることがあれば、お知らせください。ありがとうございました!