创建了使用PHPmailer发送邮件的功能。但它不起作用
我使用phpmailer创建了一个php函数来发送邮件。但是,函数中存在一个问题。它既不发送邮件也不显示错误。请帮帮我。我正在从其他功能获取邮件正文和一些其他详细信息,它工作正常,只是它不发送邮件,我认为主机、端口、用户名等肯定有问题。 请帮帮我。 谢谢 我的职能:创建了使用PHPmailer发送邮件的功能。但它不起作用,php,api,phpmailer,Php,Api,Phpmailer,我使用phpmailer创建了一个php函数来发送邮件。但是,函数中存在一个问题。它既不发送邮件也不显示错误。请帮帮我。我正在从其他功能获取邮件正文和一些其他详细信息,它工作正常,只是它不发送邮件,我认为主机、端口、用户名等肯定有问题。 请帮帮我。 谢谢 我的职能: public static function sendEmail($data) { $r_error = 1; $r_message = ""; $r_data = array();
public static function sendEmail($data) {
$r_error = 1;
$r_message = "";
$r_data = array();
$q = "select * from config where type='email_detail'";
$r = self::DBrunQuery($q);
$row = self::DBfetchRow($r);
$detail = json_decode($row['value'], true);
include "phpmailer/PHPMailerAutoload.php";
if (!empty($data['email'])) {
foreach ($data as $var) {
$work_email = 'fahadansari12feb@gmail.com'; //$var['email_id'];
$name = 'fahad'; //$var['name'];
$subject = $var['subject'];
$body = $var['body'];
$cc = $var['cc_detail'];
$bcc = $var['bcc_detail'];
$file_upload = $var['upload_file'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = '5.9.144.226'; //$detail['host'];
$mail->Port = '2222'; //$detail['port'];
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'fahadansari12feb@gmail.com'; //$detail['username']; //sender email address
$mail->Password = 'mypassword'; //$detail['password']; // sender email password
$mail->setFrom('hr@excellencetechnologies.in', 'Excellence Technologies'); // name and email address from which email is send
$mail->addReplyTo('hr@excellencetechnologies.in', 'Excellence Technologies'); // reply email address with name
$mail->addAddress($work_email, $name); // name and address to whome mail is to send
if (sizeof($cc) > 0) {
foreach ($cc as $d) {
$mail->addCC($d[0], $d[1]);
}
}
if (sizeof($bcc) > 0) {
foreach ($bcc as $d2) {
$mail->addBCC($d2[0], $d2[1]);
}
}
$mail->Subject = $subject; // subject of email message
$mail->msgHTML($body); // main message
// $mail->AltBody = 'This is a plain-text message body';
//Attach an image file
if (sizeof($file_upload) > 0) {
foreach ($file_upload as $d3) {
$mail->addAttachment($d3);
}
}
//send the message, check for errors
if (!$mail->send()) {
$row3 = $mail->ErrorInfo;
} else {
$row3 = "Message sent";
}
}
}
if ($row3 != "Message sent") {
$r_error = 1;
$r_message = $row3;
$r_data['message'] = $r_message;
} else {
$r_error = 0;
$r_message = "Message Sent";
$r_data['message'] = $r_message;
}
$return = array();
$return['error'] = $r_error;
$return['data'] = $r_data;
return $return;
}
你没有发布足够的信息,但我会猜你的问题。您正在启用TLS,但连接到的是IP地址而不是主机名,因此您的主机名将永远不会与证书上的名称匹配,并且您将在SMTP连接上遇到TLS验证失败 使用有效证书连接到命名主机,或禁用证书检查(有关如何执行此操作的信息,请参阅PHPMailer文档),但不建议这样做
您还使用了旧版本的PHPMailer,因此请升级。您是否绝对确保您的脚本达到
if(!$mail->send()){
line?它显示smtp连接错误。你需要查看,你需要谷歌搜索——如果你仍然无法让它工作,回来讨论你在尝试这些东西时遇到的问题,以及为什么这些东西对你不起作用。