为员工CRM保存电子邮件到mysql

时间:2012-01-09 00:29:22

标签: php mysql email

我有一个我建立的客户关系系统,我想知道的是将电子邮件保存到mysql的最佳方法是什么,所以我不必为每个员工创建一个实际的电子邮件地址,因为我们有工作人员访问CRM而不是前景。

如果有任何文档可以提供帮助。

3 个答案:

答案 0 :(得分:1)

如果您不忘记记录标题,电子邮件本身已经包含了所有必要的数据。

您必须绝对保留完整标题,因为如果客户遇到任何问题,它将非常有用。只有标题才是证据。

当然,您必须在mysql中添加有关您的个性化数据的列:customer_id,user_id以及您需要的任何CRM。

除此之外,即使它们在电子邮件中,您也可以添加一些可能对您有用的mysql列:date,subject,user_to,address_from ......这一切都取决于您对它们的使用。

我想我会在BLOB中保留电子邮件的全部内容,因为可以附加文件。它最终可能超过10MB ......

答案 1 :(得分:1)

数据库结构:这只是一些伪sql,可以向您展示可以用于表结构的内容..

CREATE table `emails`
id int auto_increment primary_key
email_to varchar 255
email_cc varchar 255
email_bcc varchar 255
email_from varchar 255
email_subject varchar 255
email_message text
customer_id int
user_id int

#use this field to flag the email to be sent
#i use a cron task that sends x emails per x minutes 
#to avoid spam filtering and black listing
email_flag ENUM (0,1) default 0
email_sent_timestamp int
email_created_timestamp int
email_has_attachments ENUM (0,1) default 0

#this will be a serialized field of filenames
#using a naming convention as such: user_id_timestamp.pdf
#that you could use php to split and return. 
#IE: 13_15648461867.pdf;14_5186484834.jpg
email_attachments text

文件上传: 我个人不建议使用mysql来存储文件,特别是如果它们非常大的话。在发送电子邮件之前,更容易使用php及其文件interactiosn上传到目录。

将文件存储在名为chmod 777

/uploads文件夹中

文件上传示例。此上传为临时文件名并检查其是否存在。 Google搜索提供了此代码段。 http://www.tizag.com/phpT/fileupload.php

<?php
$target_path = "/uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

将文件名存储在数据库表中。在发送电子邮件附加文档时,使用PHP split和foreach。

<?php
$attachments = split(";", $email_attachments);
foreach ($attachments as $a){
    // attachments code here, see php mail()
    // http://www.php.net/manual/en/function.mail.php#105661
}
//create a script that doesn't have web access 
//to be initiated via cron that connects to the `emails` table
//and retrieves all emails that are email_flag=0
//put them into array, and loop through 10 at a time for every 5 minutes
//send out the email
//set email_flag to 1
?>

如果您需要实际代码示例,请与我们联系。我可以把一个有效的例子放在一起。

答案 2 :(得分:0)

我认为“电子邮件”几乎意味着“发布”。所以只需创建mysql表:id,user_id,email_id并在其中保存电子邮件。