我已经尝试了好几天,试图将一段PHPMailer代码合并到一个WordPress插件中,但没有成功。我很乐意走另一条路,只要它能实现通过一个联系表单提交发送两封单独的电子邮件的目标:1,在联系人中输入电子邮件地址,并带有固定的信息、主题和附件;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
}
?>
任何和所有的帮助都将非常感激,如果我能做更多的事情来阐明我的问题和/或增加其可理解性,请让我知道。谢谢你!
您可以使用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