[英]PHPMailer or wp_mail integration to Plugin - Or Alternative? Contact Submit to send two seperate emails with attachments
我已经尝试了好几天,将一段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
}
?>
任何帮助都将不胜感激,如果我能做更多事情来阐明我的问题和/或提高其可理解性,请告诉我。 谢谢!
您可以使用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';
}
?>
有关更多信息,请参考以下链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.