【发布时间】:2023-08-11 07:26:02
【问题描述】:
嗨,我有三四页 1.配置文件 2.表格文件 3.form执行文件 4.发送php邮件文件 如果我要使用 phpmmailer,一切都很好,如果我要添加 phpmailer 代码,然后在发送邮件代码之后,其余代码不起作用。
我显示 500 内部服务器错误
执行文件代码:
sendCustomerMail($myassigneduser->email, "Customer Status Change", "templatefile.php", $message, $headers, $other);
$db = new db();
发送邮件文件:
<?php
//in this code i'm getting error
require 'phpmailer/PHPMailerAutoload.php';
$templatepath = $_SERVER['DOCUMENT_ROOT'].'/customer/Templates/';
$body = file_get_contents($templatepath.$template_name);
$other['--TEMPLATE_URL--'] = $templatepath;
foreach($other as $k => $v) {
$body = str_replace($k,$v,$body);
}
$body = wordwrap(trim($body), 70, "\r\n");
$body = convert_smart_quotes($body);
$mail = new PHPMailer;
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = $email_hostname;
$mail->Username = $email_username;
$mail->Password = $email_password;
$mail->setFrom($from_email, $company_name);
$mail->addReplyTo($from_email, $company_name);
$mail->addAddress($to, '');
$mail->Subject = $subject;
$mail->msgHTML($body);
if (!$mail->send()) {
return 1;
} else {
return 0;
}
//if i'm use simple php mail whole code is working fine
$headers = 'From:'.$from_email.'' . "\r\n" .'Reply-To:'.$from_email.'' . "\r\n" .'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templatepath = $_SERVER['DOCUMENT_ROOT'].'/customer/Templates/';
$body = file_get_contents($templatepath.$template_name);
$other['--TEMPLATE_URL--'] = $templatepath;
foreach($other as $k => $v) {
$body = str_replace($k,$v,$body);
}
$body = wordwrap(trim($body), 70, "\r\n");
$body = convert_smart_quotes($body);
if (mail($to,$subject,$body,$headers)) {
return 1;
}else{
return 0;
}
?>
注意:所有代码都通过 ajax 工作
【问题讨论】:
-
做一些基本的 PHP 调试,阅读一些文档,查看你的 web 服务器日志,它会显示错误。
-
好的,谢谢,我会做的。
标签: php ajax email smtp phpmailer