默认drupal_mail()函数不包含附件的功能。互联网搜索,很多人建议使用mimemail module,但没有提供以它如何能够从你的代码中使用的建议。
这是Mime Mail模块安装截图。
如何使用MIME Mail
下面是英文参数说明:
+/**
+ * Sends a mime-encoded e-mail.
+ *
+ * This function first determines the mail engine to use, then prepares the
+ * message by calling the mail engine's prepare function, or
+ * mimemail_prepare() if another one does not exist, then sends the message.
+ *
+ * @param $sender
+ * The email address or user object who is sending the message.
+ * @param $recipient
+ * An email address or user object who is receiving the message.
+ * @param $subject
+ * A subject line string.
+ * @param $body
+ * The message body in HTML format.
+ * @param $plaintext
+ * Whether to send the message as plaintext only or HTML. If set to 1, Yes
+ * or TRUE, then the message will be sent as plaintext.
+ * @param $headers
+ * Optional e-mail headers in a keyed array.
+ * @param $text
+ * Optional plaintext portion of a multipart e-mail (instead of auto-generated).
+ * @param $attachments
+ * An array of arrays which describe one or more attachments. The internal
+ * array consists of two parts: the file's path and the file's MIME type.
+ * The array of arrays looks something like this:
+ * Array
+ * (
+ * [0] => Array
+ * (
+ * [filepath] => '/path/to/file.name'
+ * [filemime] => 'mime/type'
+ * )
+ * )
+ * @param $mailkey
+ * An identifier for the message.
+ * @return
+ * An array containing the MIME encoded message, including headers and body.
+ */
发送Email的方法:
- 你必须下载并启用mimemail模块,然后你就可以在程序中使用mimemail函数
- 发送的电子邮件的内容中使用的CSS。我想补充的覆盖功能,这是我的template.php文件像这样:
function phptemplate_mimemail_message($body, $mailkey = null){
return $body;
}
其他模块中使用方法:
global $base_url; //系统网址
$sender = variable_get(‘site_mail’, ini_get(‘sendmail_from’)); //后台配置的邮件发送者
$title = variable_get(‘site_name’, ‘Drupal’); //系统站点名称
//pdf文件附件发送, 这里我上传的文件位于:/sites/default/files/lixiphp高级编程.pdf,注意对比自己的文件路径。
$attachments[]=array(
‘filepath’ => file_directory_path().’/lixiphp高级编程.pdf’, //要注意的事项, 文件路径从文档根目录而不是从服务器的根。
‘filename’ => ‘lixiphp高级编程.pdf’,
‘filemime’ => ‘application/pdf’,
);
mimemail($sender,$recipient,$title,$user_body,NULL,array(),NULL,$attachments,”);
多个接收邮件人,邮件使用“,”分开,比如
$recipient = ‘admin@lixiphp.com,service@lixiphp.com,lixiphp@qq.com’; //只能使用user object和字符串变量
阅读更多>>
标签: attachment, drupal, mail, mime