几天来,我尝试将一段运行良好的 PHPMailer 代码合并到一个 WordPress 插件中,但成功率为零。我很乐意走另一条路线,只要它达到通过一个联系表单提交发送两封单独电子邮件的目标:1,到输入联系人的电子邮件地址,带有固定的消息、主题和附件;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
}
?>
任何和所有的帮助将不胜感激,如果我能做更多的事情来表达我的问题和/或增加它的可理解性,请告诉我。谢谢!