PHP-致命错误:找不到类’Swift_smtpTransport’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP-致命错误:找不到类’Swift_smtpTransport’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6217字,纯文字阅读大概需要9分钟。
内容图文
![PHP-致命错误:找不到类’Swift_smtpTransport’](/upload/InfoBanner/zyjiaocheng/692/dd615d4bc3be471e93e2e2125d339333.jpg)
我正在尝试添加从我的网站后端向客户发送电子邮件的功能,并试图使用swiftmailer做到这一点.
不幸的是,我一直收到错误消息
Fatal error: Class 'Swift_smtpTransport' not found in /home/u312041955/public_html/cust/modules/customer/email.php on line 94
尽管在我看来,swiftmailer类未正确包含,但必须这样,否则该页面根本不会显示任何信息.
我正在使用swiftmailer的页面中的代码如下.
<?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();
}
?>
我现在或一段时间以来一直在为此苦苦挣扎,可以朝正确的方向推一下.
更新1:我一直在继续玩这个游戏,当我换线时
$transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 )
->setUsername('noreply@example.co.uk')
->setPassword('******');
简单地
$transport = Swift_MailTransport::newInstance()
所以它不再使用SMTP了,我收到一条成功发送通知的消息,但由于某种原因,它将其发送到发自电子邮件地址,并且也被标记为垃圾邮件,因为它可能不是源自帐户,因此为什么要使用smtp.
更新2:阅读其他线程后,我发现
$transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 );
实际上应该是
$transport = Swift_SmtpTransport::newyInstance( "mx1.hostinger.co.uk" , 2525 )
;
这摆脱了类未找到的错误,但是我现在遇到了超时错误.我可以肯定我使用的是正确的邮件服务器详细信息,因为我是从主机那里获得的.
任何帮助,非常感谢.
解决方法:
最终解决了
$transport = Swift_smtpTransport::newInstance( "mx1.hostinger.co.uk" , 2525 );
实际上应该是
$transport = Swift_SmtpTransport::newyInstance( "mx1.hostinger.co.uk" , 2525 );
然后我的托管服务提供商不允许我的计划中的SMTP发送邮件.
内容总结
以上是互联网集市为您收集整理的PHP-致命错误:找不到类’Swift_smtpTransport’全部内容,希望文章能够帮你解决PHP-致命错误:找不到类’Swift_smtpTransport’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。