致命错误:没有找到类“Swift_smtpTransport” [英] Fatal error: Class 'Swift_smtpTransport' not found in

查看:301
本文介绍了致命错误:没有找到类“Swift_smtpTransport”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加从我的网站后端发送客户邮件的功能,并尝试使用swiftmailer来执行此操作。
我不幸的是收到一条错误消息

 致命错误:类别Swift_smtpTransport找不到/ home / u312041955 / public_html / cust / modules / customer / email.php on line 94 

虽然我似乎像swiftmailer类没有被正确地包括在内,所以它必须是否,否则页面根本不显示任何信息。
从我使用swiftmailer的页面中的代码如下。

 <?php require_once(include .PHP); 
// swift mailer需要
require_once(INCLUDE_URL。'/ swift / lib / swift_required.php');
如果(!xml2php(customer)){
$ smarty-> assign('error_msg',语言文件中的错误);
}
//让我们获取一些我们需要的变量
$ email_username = $ VAR ['email_username'];
$ email_password = $ VAR ['email_password'];
$ email_server = $ VAR ['email_server2'];
$ email_server_port = $ VAR ['email_server_port2'];
$ customer_id = $ VAR ['customer_id'];
$ c2 = $ VAR ['c2'];
$ download_id = $ VAR ['download_id'];
$ submit = $ VAR ['submit'];
$ email_to = $ VAR ['email_to'];
$ email_from = $ VAR ['email_from'];
$ email_subject = $ VAR ['email_subject'];
$ message_body = $ VAR ['message_body'];
$ attachment = $ VAR ['attachment'];
$ rr_email = $ VAR ['rr'];
$ cus_name = $ VAR ['cus_name'];
$ sig =< br> Regards,< br>$ employee_details ['EMPLOYEE_FIRST_NAME']。< br> MD-PC

//获取所有客户电子邮件
$ q =SELECT * FROM.PRFX。TABLE_CUSTOMER_EMAILS WHERE CUSTOMER_ID ='。$ customer_id。'ORDER BY CUSTOMER_EMAIL_ID DESC;
$ rs = $ db-> Execute($ q);
$ customer_emails = $ rs-> GetArray();
$ smarty-> assign('customer_emails',$ customer_emails);
/ *获取客户信息* /
$ q =SELECT * FROM.PRFX。TABLE_CUSTOMER WHERE CUSTOMER_ID ='。$ customer_id。';
$ rs = $ db-> Execute($ q);
$ customer_details = $ rs-> GetArray();
$ smarty-> assign('customer_details',$ customer_details);
/ *获取员工信息* /
$ q =SELECT * FROM.PRFX。TABLE_EMPLOYEE WHERE EMPLOYEE_DISPLAY_NAME ='。$ login。';
$ rs = $ db-> Execute($ q);
$ employee_details = $ rs-> FetchRow();
$ smarty-> assign('employee_details',$ employee_details);
//分配数组
$ smarty-> assign('open_work_orders',display_open_workorders($ db,$ customer_id));
$ smarty-> assign('closed_work_orders',display_closed_workorders($ db,$ customer_id));
// $ smarty-> assign('customer_details',display_customer_info($ db,$ customer_id));
$ smarty-> assign('customer_details',$ customer_details);
$ smarty-> assign('unpaid_invoices',display_unpaid_invoices($ db,$ customer_id));
$ smarty-> assign('paid_invoices',display_paid_invoices($ db,$ customer_id));
$ smarty-> assign('memo',display_memo($ db,$ customer_id));
$ smarty-> assign('gift',display_gift($ db,$ customer_id));
$ smarty-> assign('company_details',display_company_info($ db,$ company_id));
// Lets获取下载的文件,从数据库中查看
if(isset($ download_id)){
/ *获取所有客户电子邮件* /
$ q =SELECT CUSTOMER_EMAIL_ATT_NAME1,CUSTOMER_EMAIL_ATT_TYPE1,CUSTOMER_EMAIL_ATT_SIZE1,CUSTOMER_EMAIL_ATT_FILE1,FROM.PRFX。TABLE_CUSTOMER_EMAILS WHERE CUSTOMER_EMAIL_ID ='。$ download_id。';
$ rs = $ db-> Execute($ q);
// header(Content-length:$ rs-> fields ['CUSTOMER_EMAIL_ATT_SIZE1']);
// header(Content-type:$ rs-> fields ['CUSTOMER_EMAIL_ATT_TYPE1']);
// header(Content-Disposition:attachment; filename = $ rs-> fields ['CUSTOMER_EMAIL_ATT_NAME1']);
$ file_download = $ rs-> fields ['CUSTOMER_EMAIL_ATT_FILE1'];
$ smarty-> assign('file_download',$ file_download);
//打印$ CUSTOMER_EMAIL_ATT_NAME1;
退出;

}
// BOF电子邮件消息详细信息
//邮件
if(isset($ submit)){
if($ _ FILES ['attachment1 '] ['size']> 0){
$ fp = fopen($ _ FILES ['attachment1'] ['tmp_name'],'r');
$ content1 = fread($ fp,filesize($ _ FILES ['attachment1'] ['tmp_name']));
$ content1 = addslashes($ content1);
fclose($ fp);
}
$ sql =INSERT INTO.PRFX。TABLE_CUSTOMER_EMAILS SET
CUSTOMER_ID =。 $ db-> qstr($ VAR [c2])。,
CUSTOMER_EMAIL_ADDRESS =。 $ db-> qstr($ VAR [email_to])。,
CUSTOMER_FROM_EMAIL_ADDRESS =。 $ db-> qstr($ VAR [email_from])。,
CUSTOMER_EMAIL_SENT_BY =。 $ db-> qstr($ login)。,
CUSTOMER_EMAIL_SENT_ON =。 $ db-> qstr(time())。,
CUSTOMER_EMAIL_SUBJECT =。 $ db-> qstr($ VAR [email_subject])。,
CUSTOMER_EMAIL_BODY =。 $ db-> qstr($ VAR [message_body])。,
CUSTOMER_EMAIL_ATT_NAME1 =。 $ db-> qstr($ _FILES ['attachment1'] ['name'])。,
CUSTOMER_EMAIL_ATT_TYPE1 =。 $ db-> qstr($ _FILES ['attachment1'] ['type'])。,
CUSTOMER_EMAIL_ATT_SIZE1 =。 $ db-> qstr($ _FILES ['attachment1'] ['size'])。,
CUSTOMER_EMAIL_ATT_FILE1 =。 $ db-> qstr($ content1);



如果(!$ result = $ db-> Execute($ sql)){
force_page('core','error& error_msg =错误:'。$ db-> ErrorMsg()。& menu = 1& type = database');
退出;
}
// print $ sql;
$ transport = Swift_smtpTransport :: newInstance(mx1.hostinger.co.uk,2525)
- > setUsername('noreply@example.co.uk')
- >设置密码('******');
$ mailer = Swift_Mailer :: newInstance($ transport);
//创建一个消息
$ message = Swift_Message :: newInstance($ email_subject)
- > setFrom(array($ email_from => $ employee_details ['EMPLOYEE_FIRST_NAME']))
- > setTo(array($ email_to => $ cus_name))
- > setBody($ strip)
- > addPart('Hello'。$ cus_name,'text / html')
- > addPart($ message_body,'text / plain')
- > attach(Swift_Attachment :: fromPath($ target_path));
//发送消息
$ numSent = $ mailer-> send($ message);
//显示发送的消息数
echo< script> alert('Email Information')< / script>;
echoSent%d messages\\\
,$ numSent;
exit();

}
?>

我现在或者一段时间一直在努力,可以用正确的方向推动。



更新1:我一直在继续玩这个,当我改变线路

 $ transport = Swift_smtpTransport :: newInstance(mx1.hostinger.co.uk,2525)
- > setUsername('noreply@example.co.uk')
- > setPassword( '******');

简单地

 code> $ transport = Swift_MailTransport :: newInstance()

所以没有使用SMTP我得到一个消息发送成功通知,但由于某些原因,它将其发送到电子邮件地址,也被标记为垃圾邮件,因为它可能没有源自该帐户,因此我为什么要使用smtp。
更新2:在阅读其他线程后,我发现

  $ transport = Swift_smtpTransport :: newInstance(mx1.hostinger .co.uk,2525); 

其实应该是

 $ $ $ $ $ $ SW = 

这将摆脱类未找到的错误,但我现在得到一个超时错误。我确信我正在使用正确的邮件服务器详细信息,因为我从我的主机收到他们。
任何帮助非常感谢。

解决方案

最终确定了

  $ transport = Swift_smtpTransport :: newInstance(mx1.hostinger.co.uk,2525); 

其实应该是

  $ transport = Swift_SmtpTransport :: newyInstance(mx1.hostinger.co.uk,2525); 

然后,我的托管服务提供商不允许SMTP在我的计划上发送邮件。 / p>

I am trying to add the functionality to send my customers emails from my website backend and am attempting to use swiftmailer to do this. I unfortunately keep getting an error message

Fatal error: Class 'Swift_smtpTransport' not found in /home/u312041955/public_html/cust/modules/customer/email.php on line 94

Although it seem to me like the swiftmailer class is not being included properly it must be as otherwise the page does not display any information at all. The code from the page I am using swiftmailer from is as follows.

<?php require_once("include.php");
    //Required for swift mailer
    require_once (INCLUDE_URL.'/swift/lib/swift_required.php');
    if(!xml2php("customer")) {
    $smarty->assign('error_msg',"Error in language file");
    }
    // Lets grab some variables we need
    $email_username = $VAR['email_username'];
    $email_password = $VAR['email_password'];
    $email_server = $VAR['email_server2'];
    $email_server_port = $VAR['email_server_port2'];
    $customer_id = $VAR['customer_id'];
    $c2 = $VAR['c2'];
    $download_id = $VAR['download_id'];
    $submit = $VAR['submit'];
    $email_to = $VAR['email_to'];
    $email_from = $VAR['email_from'];
    $email_subject = $VAR['email_subject'];
    $message_body = $VAR['message_body'];
    $attachment = $VAR['attachment'];
    $rr_email = $VAR['rr'];
    $cus_name = $VAR['cus_name'];
    $sig = "<br>Regards,<br>".$employee_details ['EMPLOYEE_FIRST_NAME']."<br>MD-PC";

//Get All customer Emails
$q = "SELECT * FROM ".PRFX."TABLE_CUSTOMER_EMAILS WHERE CUSTOMER_ID ='".$customer_id."' ORDER BY CUSTOMER_EMAIL_ID DESC" ;
$rs = $db->Execute($q);
$customer_emails = $rs->GetArray();
$smarty->assign('customer_emails', $customer_emails);
/*Get Customer Info */
$q = "SELECT * FROM ".PRFX."TABLE_CUSTOMER WHERE CUSTOMER_ID ='".$customer_id."'" ;
$rs = $db->Execute($q);
$customer_details = $rs->GetArray();
$smarty->assign('customer_details', $customer_details);
/*Get Employee Info */
$q = "SELECT * FROM ".PRFX."TABLE_EMPLOYEE WHERE EMPLOYEE_DISPLAY_NAME ='".$login."'" ;
$rs = $db->Execute($q);
$employee_details = $rs->FetchRow();
$smarty->assign('employee_details', $employee_details);
// assign the arrays
$smarty->assign('open_work_orders', display_open_workorders($db, $customer_id));
$smarty->assign('closed_work_orders',   display_closed_workorders($db, $customer_id));
//$smarty->assign('customer_details',   display_customer_info($db, $customer_id));
$smarty->assign('customer_details',$customer_details);
$smarty->assign('unpaid_invoices', display_unpaid_invoices($db,$customer_id));
$smarty->assign('paid_invoices', display_paid_invoices($db,$customer_id));
$smarty->assign('memo', display_memo($db,$customer_id));
$smarty->assign('gift', display_gift($db, $customer_id));
$smarty->assign('company_details',display_company_info($db, $company_id));
//Lets Get the file downloaded to have a look at it from the database
if(isset ($download_id)){
 /*Get All customer Emails */
$q = "SELECT CUSTOMER_EMAIL_ATT_NAME1, CUSTOMER_EMAIL_ATT_TYPE1, CUSTOMER_EMAIL_ATT_SIZE1, CUSTOMER_EMAIL_ATT_FILE1,  FROM ".PRFX."TABLE_CUSTOMER_EMAILS WHERE CUSTOMER_EMAIL_ID ='".$download_id."'" ;
$rs = $db->Execute($q);
//header("Content-length: $rs->fields['CUSTOMER_EMAIL_ATT_SIZE1']");
//header("Content-type: $rs->fields['CUSTOMER_EMAIL_ATT_TYPE1']");
//header("Content-Disposition: attachment; filename=$rs->fields['CUSTOMER_EMAIL_ATT_NAME1']");
$file_download= $rs->fields['CUSTOMER_EMAIL_ATT_FILE1'];
$smarty->assign('file_download', $file_download);
//Print $CUSTOMER_EMAIL_ATT_NAME1;
 exit;

 }
// BOF Email Message details
//Mail
if(isset ($submit)){
    if($_FILES['attachment1']['size'] >  0 ){
    $fp      = fopen($_FILES['attachment1']['tmp_name'], 'r');
    $content1 = fread($fp, filesize($_FILES['attachment1']['tmp_name']));
    $content1 = addslashes($content1);
    fclose($fp);
    }
    $sql = "INSERT INTO ".PRFX."TABLE_CUSTOMER_EMAILS SET
            CUSTOMER_ID             = ". $db->qstr($VAR["c2"]).",
            CUSTOMER_EMAIL_ADDRESS  = ". $db->qstr( $VAR["email_to"]).",
            CUSTOMER_FROM_EMAIL_ADDRESS = ". $db->qstr( $VAR["email_from"]).",
            CUSTOMER_EMAIL_SENT_BY      = ". $db->qstr( $login ).", 
            CUSTOMER_EMAIL_SENT_ON      = ". $db->qstr( time()).",
            CUSTOMER_EMAIL_SUBJECT      = ". $db->qstr( $VAR["email_subject"]).",
            CUSTOMER_EMAIL_BODY = ". $db->qstr( $VAR["message_body"]).",
            CUSTOMER_EMAIL_ATT_NAME1    = ". $db->qstr( $_FILES['attachment1']['name']).",
            CUSTOMER_EMAIL_ATT_TYPE1        = ". $db->qstr( $_FILES['attachment1']['type']).",
            CUSTOMER_EMAIL_ATT_SIZE1        = ". $db->qstr( $_FILES['attachment1']['size']).",
            CUSTOMER_EMAIL_ATT_FILE1    = ". $db->qstr( $content1 ); 



    if(!$result = $db->Execute($sql)) {
        force_page('core', 'error&error_msg=MySQL Error: '.$db->ErrorMsg().'&menu=1&type=database');
        exit;
    }
//print $sql ;
    $transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 )
    ->setUsername('noreply@example.co.uk')
    ->setPassword('******');
    $mailer = Swift_Mailer::newInstance($transport);
    //Create a message
    $message = Swift_Message::newInstance($email_subject)
      ->setFrom(array($email_from => $employee_details['EMPLOYEE_FIRST_NAME']))
     ->setTo(array($email_to => $cus_name))
     ->setBody($strip )
     ->addPart('Hello '.$cus_name , 'text/html')
     ->addPart($message_body, 'text/plain')
     ->attach(Swift_Attachment::fromPath($target_path));
     //Send the message
     $numSent = $mailer->send($message);
     //Display how many messages were sent
     echo "<script>alert('Email Information')</script>";
     echo "Sent %d messages\n", $numSent;
     exit(); 

    }
    ?>

I have been struggling with this now or some time and could use a shove in the right direction.

Update 1: I have been continuing to play around with this and when i change the line

$transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 )
->setUsername('noreply@example.co.uk')
->setPassword('******');

To simply

$transport = Swift_MailTransport::newInstance()

so it isn't using SMTP anymore i get a message sent successfully notification but for some reason it sends it to the from email address and also gets marked as spam because it may not have originated from the account hence why I want to use smtp. Update 2: after reading other threads I found that

$transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 );

Should in fact be

$transport = Swift_SmtpTransport::newyInstance( "mx1.hostinger.co.uk" , 2525 )
;

This gets rid of the class not found error but I now get a timeout error. I am certain I am using the correct mail server detail as I got them from my host. Any help very much appreciated.

解决方案

Eventually worked out that

$transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 );

Should in fact be

$transport = Swift_SmtpTransport::newyInstance( "mx1.hostinger.co.uk" , 2525 );

and then afterwards that my hosting provider does not allow mail to be sent by SMTP on my plan.

这篇关于致命错误:没有找到类“Swift_smtpTransport”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆